plot with multiple images and colorbar

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

plot with multiple images and colorbar

Slavin, Jonathan
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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: plot with multiple images and colorbar

Jody Klymak
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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Jody Klymak    






_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: plot with multiple images and colorbar

Slavin, Jonathan
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 <[hidden email]> 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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Jody Klymak    







--
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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users