# Save a figure with a specific size with a subplot of a specific size in Plots.jl (with PGFPlotsX backend)

**URL:** <https://discourse.julialang.org/t/save-a-figure-with-a-specific-size-with-a-subplot-of-a-specific-size-in-plots-jl-with-pgfplotsx-backend/86614>\
**Category:** Visualization\
**Tags:** plots, pgfplotsx\
**Created:** [August 31, 2022, 6:47pm UTC](https://discourse.julialang.org/t/save-a-figure-with-a-specific-size-with-a-subplot-of-a-specific-size-in-plots-jl-with-pgfplotsx-backend/86614 "2022-08-31T18:47:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [August 31, 2022, 6:47pm UTC](https://discourse.julialang.org/t/save-a-figure-with-a-specific-size-with-a-subplot-of-a-specific-size-in-plots-jl-with-pgfplotsx-backend/86614/1 "2022-08-31T18:47:58Z")

</div>

In PyPlot, I can output a figure with a specific size containing an axis in the figure with a specific size using the code:

```julia
using PyPlot
fig_width = 4.0
fig_height = 3.0
fig = figure( figsize = (fig_width, fig_height) )
ax = plt.axes( [0.5,0.5,0.1,0.1] )
ax.plot( [0,1] , [0,1] )
savefig("pyplot_output.pdf")

```

This will create a pdf that is 4 inches wide and 3 inches high, and an axis that has its lower left corner in the middle of the figure and is 10% of the figure wide and 10% of the figure high.

Is it possible to to achieve the same outcome using Plots.jl with the PGFPlotsX backend? I.e., can I 1: Specify the output size of the figure? 2: Specify the relative size of the axis within the figure?

I feel a bit silly asking such a basic question, but even after reading the Plots.jl documentation and Googling around, I could not figure out how to do this.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [September 1, 2022, 5:33am UTC](https://discourse.julialang.org/t/save-a-figure-with-a-specific-size-with-a-subplot-of-a-specific-size-in-plots-jl-with-pgfplotsx-backend/86614/2 "2022-09-01T05:33:43Z")

</div>

You can pass backend-specific keyword arguments from Plots.jl using `extra_kwargs`. For example:

```julia
using Plots; pgfplotsx()
fig_width = 4.0
fig_height = 3.0

plot(Plots.fakedata(50, 5), extra_kwargs =Dict(:subplot=>Dict("height" => "$(fig_height)in", "width" => "$(fig_width)in")))

```

See:  
[https://docs.juliaplots.org/stable/backends/#Fine-tuning-4](https://docs.juliaplots.org/stable/backends/#Fine-tuning-4)  
[https://docs.juliaplots.org/stable/generated/attributes\_plot/](https://docs.juliaplots.org/stable/generated/attributes_plot/)  
[https://kristofferc.github.io/PGFPlotsX.jl/stable/examples/gallery/#Mixing-expression-and-coordinates](https://kristofferc.github.io/PGFPlotsX.jl/stable/examples/gallery/#Mixing-expression-and-coordinates)

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [September 1, 2022, 3:02pm UTC](https://discourse.julialang.org/t/save-a-figure-with-a-specific-size-with-a-subplot-of-a-specific-size-in-plots-jl-with-pgfplotsx-backend/86614/3 "2022-09-01T15:02:54Z")

</div>

Thanks! I’ll have a look and see if I can figure it out. The particular example does unfortunately not quite work–it produces a pdf that is approximately 4.33 times 2.68 inches big.
