proplot-dev / proplot

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

Colorbars within figures #377

Closed pratiman-91 closed 1 year ago

pratiman-91 commented 1 year ago

Description

Unable to produce colorbars within different subplots. Matplotlib is able to produce a better colorbar.

Steps to reproduce in Matplotlib

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

fig, axs = plt.subplots(3, 3, constrained_layout=True)
for ax in axs.flat:
    pcm = ax.pcolormesh(np.random.random((20, 20)))

fig.colorbar(pcm, ax=axs[0, :2], shrink=0.6, location='bottom')
fig.colorbar(pcm, ax=[axs[0, 2]], location='bottom')
fig.colorbar(pcm, ax=axs[1:, :], location='right', shrink=0.6)
fig.colorbar(pcm, ax=[axs[2, 1]], location='left')
plt.show()

Steps to reproduce in Proplot

import proplot as plt

fig, axs = plt.subplots(ncols=3, nrows=3)
for ax in axs:
    pcm = ax.pcolormesh(np.random.random((20, 20)))

fig.colorbar(pcm, ax=axs[0, :2], shrink=0.6, location='bottom')
fig.colorbar(pcm, ax=[axs[0, 2]], location='bottom')
fig.colorbar(pcm, ax=axs[1:, :], location='right', shrink=0.6)
fig.colorbar(pcm, ax=[axs[2, 1]], location='left')

Matplotlib behavior: [What you expected to happen] Figure 2022-07-26 154238

Proplot behavior: [What actually happened] Figure 2022-07-26 154247

Proplot version

3.4.3 Matplotlib 0.9.5 Proplot

meng630 commented 1 year ago

I encountered the same issue. I feel the Matplotlib way to locate colorbar is easier to manage (or readable) than the cols and rows setup in Proplot.

lukelbd commented 1 year ago

This error occurs because proplot's fig.colorbar does not support multiple axes arguments.

@meng630 I agree. I would like to eventually support colorbars or legends along contiguous axes with both 1) matplotlib's fig.colorbar(ax=axs[:2]) syntax and 2) a proplot-only axs[:2].colorbar() syntax (using a SubplotGrid.colorbar method). I've run into cases where I need spanning labels across inner subplots in my own work, and had to use work-arounds in those cases. Hope to tackle this sometime this summer.

Turns out I already started a thread on this topic (#329), so further comments/discussion can go there.