question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remember metadata when passing mappables to colorbar()

See original GitHub issue

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):

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()

cartopy_units

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'
)

proplot_default

Like for example (here are 3 different possibilies I am thinking): proplot_default_1 proplot_default_2 proplot_default_3

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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lukelbdcommented, Dec 9, 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.

0reactions
lukelbdcommented, 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() or colorbar() the default label is applied. Here’s a very quick example:

 import proplot as pplt
 import xarray as xr
 fig, ax = pplt.subplots()
 data = xr.DataArray(np.random.rand(10, 10), attrs={'long_name': 'variable'})
 m = ax.pcolor(data)
 ax.colorbar(m, loc='b')

cbar

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to retrieve colorbar instance from figure in matplotlib
plt.draw() or show should be called after to update plot. As the image is the mappable associated to the colorbar and can be...
Read more >
Basemap tutorial Documentation - Read the Docs
Basemap is a great tool for creating maps using python in a simple way. It's a matplotlib extension, so it has got all...
Read more >
Lab 2: Astronomical Imaging I - Astro 330 Course Book
At the end of your plotting commands, check if colorbar=True , and if so, create a colorbar via plt.colorbar() , setting the mappable...
Read more >
Customized Colorbars Tutorial - Matplotlib
This tutorial shows how to build and customize standalone colorbars, i.e. without an attached plot. Customized Colorbars#. A colorbar needs a "mappable" ( ......
Read more >
pyplot — Matplotlib 1.4.2 documentation
Detail: xerr and yerr are passed directly to errorbar(), so they can also have ... mappable: the Image, ContourSet, etc. to which the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found