proplot icon indicating copy to clipboard operation
proplot copied to clipboard

Colorbars within figures

Open pratiman-91 opened this issue 2 years ago • 1 comments

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

pratiman-91 avatar Jul 26 '22 07:07 pratiman-91

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.

meng630 avatar Sep 23 '22 20:09 meng630

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.

lukelbd avatar Mar 28 '23 23:03 lukelbd