plot with multiple images and colorbar

Hi,

I've been working on producing a figure using results of a hydro simulation
at multiple times. Because the scale of the region of interest changes over
time, I want the size of the axes to change. My goal is to make a figure
with results of four timesteps, so four images in a row, with each scaled
appropriately and with a colorbar on the right. I tried to use ImageGrid,
but that doesn't like having different axis scales for the plots - at least
it seems to always scale the y axis the same despite my best efforts -
though it does a nice job of locating the colorbar.

So I went back to subplots, but in that case the colorbar isn't the right
size, at least without tweaking the shrink parameter. Also, for some reason
there is a lot of space on the right of the plot even when I use
subplots_adjust to set right=0.99. There are many ways to place colorbars,
I know, but it would seem that my case would not be so unusual that I
should need such complex methods to do what I want. Maybe I'm missing
something. Any advice would be appreciated.

Regards,
Jon

···

--
Jonathan D. Slavin
Astrophysicist - High Energy Astrophysics Division
Center for Astrophysics | Harvard & Smithsonian
Office: (617) 496-7981 | Cell: (781) 363-0035
60 Garden Street | MS 83 | Cambridge, MA 02138
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190514/014889f2/attachment.html>

Hi Jonathan,

If you are setting the aspect ratio of your subplots, space can be missing on the RHS if the setting the aspect ratio causes the subplots to shrink horizontally. The ?solution? to this is to make your *figure* more tall and less wide until the aspect ratio shrink happens in the vertical instead of the horizontal, or don?t set the aspect ratio. Its pretty hard for matplotlib to do this automatically and still do the usual layout for axes that do not have their aspect ratio set, the desired behaviour of which is to make the axes as big as possible.

I?m working on a PR to make colorbars automatically match the height of the shown axes, rather than its place holder, but thats non-trivial.

Cheers, Jody

···

On 14 May 2019, at 08:43, Slavin, Jonathan <jslavin at cfa.harvard.edu> wrote:

Hi,

I've been working on producing a figure using results of a hydro simulation at multiple times. Because the scale of the region of interest changes over time, I want the size of the axes to change. My goal is to make a figure with results of four timesteps, so four images in a row, with each scaled appropriately and with a colorbar on the right. I tried to use ImageGrid, but that doesn't like having different axis scales for the plots - at least it seems to always scale the y axis the same despite my best efforts - though it does a nice job of locating the colorbar.

So I went back to subplots, but in that case the colorbar isn't the right size, at least without tweaking the shrink parameter. Also, for some reason there is a lot of space on the right of the plot even when I use subplots_adjust to set right=0.99. There are many ways to place colorbars, I know, but it would seem that my case would not be so unusual that I should need such complex methods to do what I want. Maybe I'm missing something. Any advice would be appreciated.

Regards,
Jon

--

Jonathan D. Slavin
Astrophysicist - High Energy Astrophysics Division
Center for Astrophysics | Harvard & Smithsonian
Office: (617) 496-7981 | Cell: (781) 363-0035
60 Garden Street | MS 83 | Cambridge, MA 02138

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Jody Klymak
http://web.uvic.ca/~jklymak/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190514/919b26f9/attachment.html>

Hi Jody,

I'm not explicitly setting the aspect ratio. It's set, I think, by the
shape of the images that are plotted via imshow. Yes, I'd like for the
height of the colorbar to match that of the plots. I am able to get it to
do that by changing the shape of the plotting window, but it'd be nicer if
it worked without having to do that.

It all looks good and works as desired when I use ImageGrid and the axis
limits are all the same, but if I try to use different ylimits then things
go wrong - even with images that have the same aspect ratio.

Jon

···

On Tue, May 14, 2019 at 12:02 PM Jody Klymak <jklymak at uvic.ca> wrote:

Hi Jonathan,

If you are setting the aspect ratio of your subplots, space can be missing
on the RHS if the setting the aspect ratio causes the subplots to shrink
horizontally. The ?solution? to this is to make your *figure* more tall
and less wide until the aspect ratio shrink happens in the vertical instead
of the horizontal, or don?t set the aspect ratio. Its pretty hard for
matplotlib to do this automatically and still do the usual layout for axes
that do not have their aspect ratio set, the desired behaviour of which is
to make the axes as big as possible.

I?m working on a PR to make colorbars automatically match the height of
the shown axes, rather than its place holder, but thats non-trivial.

Cheers, Jody

On 14 May 2019, at 08:43, Slavin, Jonathan <jslavin at cfa.harvard.edu> > wrote:

Hi,

I've been working on producing a figure using results of a hydro
simulation at multiple times. Because the scale of the region of interest
changes over time, I want the size of the axes to change. My goal is to
make a figure with results of four timesteps, so four images in a row, with
each scaled appropriately and with a colorbar on the right. I tried to use
ImageGrid, but that doesn't like having different axis scales for the plots
- at least it seems to always scale the y axis the same despite my best
efforts - though it does a nice job of locating the colorbar.

So I went back to subplots, but in that case the colorbar isn't the right
size, at least without tweaking the shrink parameter. Also, for some reason
there is a lot of space on the right of the plot even when I use
subplots_adjust to set right=0.99. There are many ways to place colorbars,
I know, but it would seem that my case would not be so unusual that I
should need such complex methods to do what I want. Maybe I'm missing
something. Any advice would be appreciated.

Regards,
Jon

--
Jonathan D. Slavin
Astrophysicist - High Energy Astrophysics Division
Center for Astrophysics | Harvard & Smithsonian
Office: (617) 496-7981 | Cell: (781) 363-0035
60 Garden Street | MS 83 | Cambridge, MA 02138

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Jody Klymak
http://web.uvic.ca/~jklymak/

--
Jonathan D. Slavin
Astrophysicist - High Energy Astrophysics Division
Center for Astrophysics | Harvard & Smithsonian
Office: (617) 496-7981 | Cell: (781) 363-0035
60 Garden Street | MS 83 | Cambridge, MA 02138
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190514/82911305/attachment-0001.html>