Closed zxdawn closed 2 years ago
BTW, extend='max'
also doesn't work.
The orientation issue was very simple -- looks like matplotlib/xarray manually manually select an appropriate "side" if the orientation
is passed but not the loc
. Previously, proplot did not do this, but now it does.
The extend issue was very subtle. Here's the rundown (mainly for future me):
pcolormesh
, then stores them in a hidden attribute on the QuadMesh
. When the result is passed to colorbar
down the line it uses those to format the colorbar.extend
from the matplotlib call to pcolormesh
, becuase outside of proplot, extend
is indeed not a valid pcolormesh
argument.PlotAxes.pcolormesh
does uses the default extend
value 'neither'
and assigns it to that hidden QuadMesh
dictionary. I have to pick some value for extend
, because it affects the DiscreteNorm
normalization.colorbar
is called, the 'neither'
value overwrites the 'max'
value that xarray has captured and sent in its internal fig.colorbar
call.I've fixed this by permitting overwriting those "hidden" parameters by passing arguments to colorbar
. This is important anyway -- passing ax.colorbar(..., locator=locs_new)
after ax.pcolor(..., colorbar_kw={'locator': locs_old})
before this fix would fail to apply locs_new
, which is kind of weird behavior.
Here's an example (before this fix, there were no triangle extensions). Note there's a caveat: because xarray internally strips extend
from the ax.pcolormesh()
call, proplot is unable to apply the correct DiscreteNorm
that assigns unique colors to out-of-bounds data. But I don't think there is any way around this.
import xarray as xr
import proplot as pplt
airtemps = xr.tutorial.open_dataset('air_temperature')
air = airtemps.air - 273.15
air2d = air.isel(time=500)
fig, axs = pplt.subplots()
air2d.plot(ax=axs, extend='both', cbar_kwargs=dict(orientation='horizontal', label='Temperature ($^{\circ}$C)'))
Description
The colorbar location can be changed in
DataArray.plot()
.Steps to reproduce
Error:
If I set the loc in
.plot()
:It doesn't work.
Expected behavior: [What you expected to happen]
Control the colorbar using
orientation
or 'loc'Equivalent steps in matplotlib
Proplot version
Paste the results of
import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)
here.