proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.11k stars 102 forks source link

Colorbars/legends spanning arbitrary contiguous subplots #329

Open lukelbd opened 2 years ago

lukelbd commented 2 years ago

In an upcoming version I'd like to support "outer" colorbars and legends spanning arbitrary contiguous subplots -- not just "figure-wide" colorbars along the figure edge. Here's a matplotlib example from this page (the top-left colorbar is what I'm thinking of... except as before, proplot would preserve colorbar widths and subplot aspect ratios):

tmp

This shouldn't be too hard to implement, and will have the benefit of unifying the clunky internal implementation of "axes-type" and "figure-type" colorbars and legends.

This is also an area where SubplotGrid could really start to shine -- similar to SubplotGrid.format, which calls figure.format(axs=axs) using the axes in the grid, I can implement SubplotGrid.colorbar and SubplotGrid.legend that respectively call figure.colorbar(axs=axs) and figure.legend(axs=axs). This would be really succinct and intuitive -- for example, if someone has a 2-row, 3-column figure, then to draw a bottom colorbar spanning the top and bottom rows, the syntax would be axs[0, :].colorbar(m, loc='bottom') followed by axs[1, :].colorbar(loc='bottom').