SkewT plot with additional panels using GridSpec #1640
-
I am trying to create a skew-T with MetPy and then add another x-y plot next to it. Ideally, I'd like the y-axis and ticks on the SkewT panel to align exactly with the y-axis and ticks of the x-y plot in the second panel. I am using GridSpec to define my containers within the figure like this:
I've figured out that in the second panel to the right of the SkewT, the only way to align the y-axes between the two panels is to re-use the code here for the SkewT plot: Namely:
This creates a plot with the specified shape the same as the SkewT panel, such that when the aspect ratio is specified it obtains the same shape. Here's what that looks like: However, the x-axis on the x-y plot to the right of the SkewT is not the same as the SkewT (i.e. not temperature). I suppose I could endlessly test and re-run to obtain the MultipleLocator step and xlim needed for the data in the right panel but is there an easier way to try and align the sizes of the plots in the two panels? Like specifying the height of the x-y plot on the right panel? Here's a sample of what it looks like: I'd be happy to add this to the example gallery once I iron out the easiest way to do this! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I was able to achieve what I needed by leveraging the What it boils down to is the aspect ratio being applied to the SkewT plot. If you set this to 'auto', you don't need to set the The easiest way to do this, is for each panel that is not the SkewT, initialize the ratio to 1. Then, for the SkewT panel start by setting the width ratio to something larger like 2 and adjust manually until you are able to get everything aligned. I was unable to figure out a recipe to use, but for my plots this worked: For a SkewT with the default MetPy x-axis range and one x-y panel to the right:
I think this is telling GridSpec to make the SkewT panel 2.5 times larger than the x-y panel. For a SkewT with x-axis of -30 to +20 and five x-y panels to the right:
And here I think this means make the SkewT panel 3.9 times larger than the other x-y panels. |
Beta Was this translation helpful? Give feedback.
I was able to achieve what I needed by leveraging the
width_ratios
parameter for GridSpec:https://matplotlib.org/api/_as_gen/matplotlib.gridspec.GridSpec.html#matplotlib.gridspec.GridSpec
What it boils down to is the aspect ratio being applied to the SkewT plot. If you set this to 'auto', you don't need to set the
width_ratios
for GridSpec and everything aligns vertically. However the SkewT then looks terrible of course.The easiest way to do this, is for each panel that is not the SkewT, initialize the ratio to 1. Then, for the SkewT panel start by setting the width ratio to something larger like 2 and adjust manually until you are able to get everything aligned. I was unable to figure …