Remember metadata when passing mappables to colorbar()
See original GitHub issueI have another suggestion of enhancement regarding what Cartopy does. By default, ProPlot uses the long_name
attribute of a DataArray as a title
of the figure, but not the units
attribute. Here is the default behavior of Cartopy when doing a plot (data: ens_avg_snow_cyclic.zip):
import xarray as xr
import proplot as plot
ens_avg_snow_cyclic = xr.open_dataarray('ens_avg_snow_cyclic.nc')
ens_avg_snow_cyclic.plot()
It automatically puts the long_name
and units
attribute of the DataArray beside the color bar. In addition, it writes as a title the coordinates left (I didn’t do any projection, the goal is only to show the labels here).
It would be nice to at least have the units
after the title in ProPlot too, in addition to the actual default behavior shown here:
f, axs = plot.subplots(proj='cyl', width=8)
m = axs[0].contourf(ens_avg_snow_cyclic, cmap='BuRd')
f.colorbar(m)
axs.format(
geogridlinewidth=0.5, geogridcolor='gray8', geogridalpha=0.5, labels=True,
coast=True, ocean=True, oceancolor='gray3', latlim=(20,90),
suptitle=str(ens_avg_snow_cyclic.season.values) + ' climatology'
)
Like for example (here are 3 different possibilies I am thinking):
Or having the same behavior as Cartopy like the 2nd example and putting as a title the left coordinates as coord_name = values
. Here it is the season, but usually, if we select a date, it shows time = ...
. After it doesn’t have to be like Cartopy, in my opinion adding at least the units would be already nice 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
@mickaellalande Thanks for letting me know – just fixed this in the latest version.
https://github.com/lukelbd/proplot/blob/0b5195284964ec49ad7bdecd5c1ef47e777892e3/proplot/wrappers.py#L647-L652
When #45 is merged these kinds of bugs will be easier to avoid.
This is now implemented on master – all “autoformat” info is now attached to outgoing handles and mappables and when they are passed into
legend()
orcolorbar()
the default label is applied. Here’s a very quick example: