# How to set the output size in \`savefig()\` in \`GR.jl\`

**URL:** <https://discourse.julialang.org/t/how-to-set-the-output-size-in-savefig-in-gr-jl/101109>\
**Category:** New to Julia\
**Tags:** question, plotting, gr\
**Created:** [July 3, 2023, 7:59am UTC](https://discourse.julialang.org/t/how-to-set-the-output-size-in-savefig-in-gr-jl/101109 "2023-07-03T07:59:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkW](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@MarkW](https://discourse.julialang.org/u/MarkW)\
**Post date:** [July 3, 2023, 7:59am UTC](https://discourse.julialang.org/t/how-to-set-the-output-size-in-savefig-in-gr-jl/101109/1 "2023-07-03T07:59:22Z")

</div>

Hi,

I have a simple question about `GR.jl` (Not through `Plots.jl`).  
I am displaying an image of size `300x300`.

I want to display it on screen and save the plot with `savefig`:

```julia
using GR

img = rand(300, 300)

imshow(img)

savefig("img.png")

```

I expect the output to have size of `300x300` yet I get much bigger size.

How can I control the output size?

I saw [Incorrect savefig size when using size = ( , ) · Issue #2303 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/2303) yet I am not sure if it is related.

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 3, 2023, 6:57pm UTC](https://discourse.julialang.org/t/how-to-set-the-output-size-in-savefig-in-gr-jl/101109/2 "2023-07-03T18:57:13Z")

</div>

An equivalent result (still) using the `GR` backend via `Plots` would be the following:

```julia
using Plots; gr()

img = rand(300, 300)
p = Plots.plot(img) # create your own here

plot!(size=(300,300))

Plots.savefig(p, "p.png") # note: savefig from Plots

```

Until you figure it out (or somebody can help with a pure `GR` solution), you can use this approach - in the end, it is still using the `GR` backend (I think `GR` is actually the default backend for `Plots` - so I don’t think you need to call `gr()`) specifically.

Later edit: By the way - without calling `plot!(size=(300,300))`, the `Plots.savefig` would also output a different size from 300x300. I think the size would be similar to the one produced by `GR`. I think a configuration method similar to the one for `Plots` should exist for `GR` (maybe it is not documented properly - I also looked at the tests, and the only thing they test for is for the resulting file to have a disk size larger than a certain value).
