# Controlling size of Gadfly plots with hstack and vstack

**URL:** <https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425>\
**Category:** New to Julia\
**Tags:** question, plotting, gadfly, vscode\
**Created:** [April 16, 2021, 5:08pm UTC](https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425 "2021-04-16T17:08:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross\_Boylan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ross_boylan/32/9210_2.png) [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Post date:** [April 16, 2021, 5:08pm UTC](https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425/1 "2021-04-16T17:08:33Z")

</div>

I am building up plots in Gadfly using hstack, and then combining those with vstack. This is in VS Code.

My main concern is that the individual subplots are excessively compressed, and I wonder how to control that. Ideally I would avoid specifying units that only worked for the particular geometry I had.

Most of the rows have 3 plots horizontally, but the last row may have fewer. In that case the plots in the last row are stretched horizontally, which I would like to avoid. How?

It would also be nice if the plots resized when I resized the window they are displayed in.

Finally, there are often way too many subplots to show reasonably in the space I have. For now I’m just requesting a subset, but it would be nice to have a better option, e.g, pop up some large window that could show them all, or have some way to scroll through them.

To recap:  
Main question: how can I control the size of subplots in hstack and vstack?

Also of interest:

1. keep geometry the same for subplots in hstacks that have fewer elements than the others.
2. Dynamic resizing of plots if the pane they are in grows.
3. How to handle very large numbers of subplots.

Here’s the current result:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/8/d8d919a8743fa99dcebe339e701bcc305b2ef6fb.png)

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [April 16, 2021, 5:20pm UTC](https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425/2 "2021-04-16T17:20:44Z")

</div>

Maybe there is a good way to control the size, but that I do not know.

What I do notice, however, is that you would probably be better off by using `Geom.subplot_grid` ([Compositing · Gadfly.jl](https://gadflyjl.org/stable/man/compositing/)); also known as a facet plot in ggplot2. That way, you avoid a lot of duplicate ticks and labels.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [April 16, 2021, 5:47pm UTC](https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425/3 "2021-04-16T17:47:43Z")

</div>

Re “a row with fewer plots” when using `hstack/vstack/gridstack`, you can include a blank `plot()`. See other examples in the [Stacks](http://gadflyjl.org/stable/man/compositing/#Stacks) section of the Gadfly docs. The size of the subplots can only be controlled by the overall plot size. As @rikh says, `Geom.subplot_grid` may be preferable here (but some geoms may fail if a subplot is empty: points should work fine as in [this example](http://gadflyjl.org/stable/gallery/scales/#Gallery_Scale.xygroup)).

---

<div class="post-metadata">

**Author:** ![Ross\_Boylan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ross_boylan/32/9210_2.png) [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Post date:** [April 16, 2021, 10:58pm UTC](https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425/4 "2021-04-16T22:58:51Z")

</div>

With facets things look better in some ways, but the overall space the plot occupies remains small. In particular it seems unaware of the space available in the plot display window of VSCode I’m using.

Is there a way to tell what it thinks the current dimensions are? `Gadfly.set_default_plot_size()` looks as if it will set the size, but I don’t see anything to read it.

The other problem with faceting is that the graphs don’t work well with a common scale for Y, so that mostly all they show is a flat line at 0.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [April 16, 2021, 11:42pm UTC](https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425/5 "2021-04-16T23:42:54Z")

</div>

I’m unsure what vscode does to the plot size, if the plot size is \> window size. `Gadfly.set_default_plot_size` definitely works e.g. in Jupyter, or when saving the figure. You might be able to get [this suggestion](https://discourse.julialang.org/t/can-i-choose-display-software/29510/3) to work in vscode, but I’ve not tested it in vscode (you might have to `popdisplay()` first, which would move Gadfly’s display to the top of the display stack).

Also see [similiar post here](https://discourse.julialang.org/t/plots-figure-size/37969).

---

<div class="post-metadata">

**Author:** ![Ross\_Boylan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ross_boylan/32/9210_2.png) [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Post date:** [April 17, 2021, 1:03am UTC](https://discourse.julialang.org/t/controlling-size-of-gadfly-plots-with-hstack-and-vstack/59425/6 "2021-04-17T01:03:56Z")

</div>

With plot size \> window size, it seems VS Code prepares the plot and then scales it down to fit the available space, preserving the aspect ratio. If I resize the pane with the graphs, they resize to fill it, subject to the aspect ratio constraint.
