You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remember metadata when passing mappables to colorbar() #81
I 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):
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:
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 :)
For now if you pass colorbar='r' or colorbar=True to your axs[0].contourf command, it will automatically label the colorbar with the long_name and units. Currently, automatic labeling is 100% controlled from plotting commands -- so it is only possible to automatically label colorbars and legends if you generate them on-the-fly by passing colorbar='r', legend='r', etc. to your plotting command.
I think I can fix this by adding a hidden _metadata attribute to artists generated by ProPlot plotting methods, and then when legend() or colorbar() receives an artist with this attribute, it can automatically apply the labels. I already do something similar for artists passed through cmap_changer.
I really like those examples! This feature should definitely be configurable. We can add keyword arguments to determine where the labels and units are placed, and maybe some rc options. I think the defaut behavior should be what it is now though -- generally units are not something that show up on axis labels, colorbars, and legends, not titles.
It wil also definitely be useful if ProPlot can try to detect singleton or "scalar" dimensions and add those values to the title, like how your example shows the time slice.
I also just realized that if I use non-cyclic data and use the option globe=True in addition to colorbar='r' the long_name and units don't show up anymore besides the color bar. It works only without the option globe=True...
changed the title [-]ProPlot doesn't use the `units` attribute of a DataArray[/-][+]Remember DataArray/Dataframe metadata when passing mappables to colorbar()[/+]on Jan 7, 2020
changed the title [-]Remember DataArray/Dataframe metadata when passing mappables to colorbar()[/-][+]Remember metadata when passing mappables to colorbar()[/+]on Jan 7, 2020
This is now implemented on master -- all "autoformat" info is now attached to outgoing handles and mappables and when they are passed into legend() or colorbar() the default label is applied. Here's a very quick example:
Activity
lukelbd commentedon Dec 4, 2019
For now if you pass
colorbar='r'orcolorbar=Trueto youraxs[0].contourfcommand, it will automatically label the colorbar with thelong_nameandunits. Currently, automatic labeling is 100% controlled from plotting commands -- so it is only possible to automatically label colorbars and legends if you generate them on-the-fly by passingcolorbar='r',legend='r', etc. to your plotting command.I think I can fix this by adding a hidden
_metadataattribute to artists generated by ProPlot plotting methods, and then whenlegend()orcolorbar()receives an artist with this attribute, it can automatically apply the labels. I already do something similar for artists passed throughcmap_changer.I really like those examples! This feature should definitely be configurable. We can add keyword arguments to determine where the labels and units are placed, and maybe some
rcoptions. I think the defaut behavior should be what it is now though -- generally units are not something that show up on axis labels, colorbars, and legends, not titles.It wil also definitely be useful if ProPlot can try to detect singleton or "scalar" dimensions and add those values to the title, like how your example shows the time slice.
mickaellalande commentedon Dec 5, 2019
Great ok, yes
colorbar='r'works well! Thus:Gives the same result as the 2nd example without having to pass the units :)
However, if I replace by
colorbar=Trueit through an error:I guess we need to set the location first?
mickaellalande commentedon Dec 5, 2019
I also just realized that if I use non-cyclic data and use the option
globe=Truein addition tocolorbar='r'thelong_nameandunitsdon't show up anymore besides the color bar. It works only without the optionglobe=True...lukelbd commentedon Dec 5, 2019
@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.
[-]ProPlot doesn't use the `units` attribute of a DataArray[/-][+]Remember DataArray/Dataframe metadata when passing mappables to colorbar()[/+][-]Remember DataArray/Dataframe metadata when passing mappables to colorbar()[/-][+]Remember metadata when passing mappables to colorbar()[/+]lukelbd commentedon Aug 18, 2021
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: