Controlling size of Gadfly plots with hstack and vstack

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:

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); also known as a facet plot in ggplot2. That way, you avoid a lot of duplicate ticks and labels.

Re “a row with fewer plots” when using hstack/vstack/gridstack, you can include a blank plot(). See other examples in the 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).

1 Like

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.

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 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.

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.