Automatically apply diverging colormaps and add `robust=True` option
See original GitHub issueIs there any way to have an automatic scaling of the colorbar when 0 is present, like the default behavior of Cartopy that center the colorbar on 0 and automatically use a diverging colormap?
And in addition, is that possible to use the option robust=True of Cartopy? When I try to use it, it tells me that it is not recognized.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Automatically apply diverging colormaps and add robust=True ...
contourf() , Xarray/Cartopy makes a symmetric color bar with a diverging colormap. Then I can use the option robust=True in my plot option...
Read more >Choosing Colormaps in Matplotlib
For many applications, a perceptually uniform colormap is the best choice; ... Diverging: change in lightness and possibly saturation of two different ...
Read more >Plotting 2D data — ProPlot documentation - Read the Docs
ProPlot adds several new features to matplotlib's plotting commands using the ... automatically applies the default diverging colormap rc['cmap.diverging'] ...
Read more >Beautiful custom colormaps with Matplotlib | by Kerry Halupka
The second chart uses a diverging colormap. With more colours it's easier to tell the difference between similar values, but it also suggests...
Read more >xarray.plot.imshow
Passing robust=True infers vmin and vmax in the usual way. Additionally the y-axis is not ... Setting both values prevents use of a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

These features are finally on master. Below is an example of the
robust=Truefeature. You can also pass a number e.g.robust=90to select colormap limits based on the middle 90 percentile range, or pass a tuple e.g.robust=(0, 90)to use that particular percentile range. As in xarray, the default percentile range implied byrobust=Trueis 96. The keyword choice is maybe a bit clunky here sincerobustcan now accept these other inputs but I’d rather stay consistent with xarray.And here’s an example of the automatic diverging colormap selection. A diverging colormap is picked as follows:
discrete=Trueandlevelsare being used, thenlevelsmust have more than one each positive and negative values.discrete=Falseand onlyvminandvmaxare being used, thenvminandvmaxmust have the opposite sign.I’ve also added a whole system for selecting default “sequential”, “diverging”, “qualitative”, and “cyclic” colormaps with corresponding rc settings and keyword arguments that can be passed to plot commands (e.g.,
rc['cmap.cyclic'] = cmapor to change the default cyclic colormap andax.pcolor(..., cyclic=True)to select the default cyclic colormap). Details are in the changelog on master (about to put these in a big release).Btw proplot has a
plot.arange(...)function that’s great for generating lists of ticks, colorbar levels, etc. Behavior is identical tonp.arangeexcept it is endpoint inclusive. So your example would beplot.arange(-45, 45, 5)rather thannp.arange(-45, 50, 5)which IMO is more intuitive.