DiscreteNorm does not support set_under/set_over colormap extremes
See original GitHub issue[Description of the bug or feature.] Error when using boudary normalization for colormap.
Steps to reproduce
A “Minimal, Complete and Verifiable Example” will make it much easier for maintainers to help you.
import matplotlib.pyplot as plt
import proplot as pplt
import numpy as np
import cmaps
import matplotlib.colors as colors
import matplotlib.ticker as ticker
state = np.random.RandomState(51423)
data = (state.rand(20, 20))*50
data[5:15,5:15] = 0.002
data[10:20,10:20] = 0.6
print(data.max(),data.min())
levels = [0.1,0.5,1.,2.,3.,4.,5.,6.,8.,10.,20.,40]
norm = colors.BoundaryNorm(boundaries=np.array(levels), ncolors=len(levels)-1)
# figure with proplot
fig, ax = pplt.subplots()
m0 = ax.contourf(data, levels=levels, extend='both', cmap=cmaps.cmorph,
colorbar="r",colorbar_kw={'ticks':levels})
ax.format(suptitle='plot with proplot')
fig.savefig('color_proplot.png')
# figure with matplotlib
fig, ax = plt.subplots()
m1 = ax.contourf(data, levels=levels, norm=norm, extend='both',cmap=cmaps.cmorph[1:])
m1.cmap.set_under(cmaps.cmorph.colors[0])
cb = plt.colorbar(m1, ax=ax, ticks=levels, extendfrac='auto',
aspect=18, shrink=.95)
cb.ax.minorticks_off()
ax.set_title("plot with matplotlib")
fig.savefig('color_matplotlib.png')
# figure with proplot and boudary normalization
fig, ax = pplt.subplots()
m0 = ax.contourf(data, levels=levels, norm=norm, extend='both', cmap=cmaps.cmorph[1:],
colorbar="r",colorbar_kw={'ticks':levels})
m0.cmap.set_under(cmaps.cmorph.colors[0])
ax.format(suptitle='plot with proplot1')
fig.savefig('color_proplot1.png')
Expected behavior: [What you expected to happen]
Actual behavior: [What actually happened]
When using default segmented normalizaton in proplot:
And when using boudary normailiztion of matplotlib:
Equivalent steps in matplotlib
See the code above.
Proplot version
0.6.1
Paste the result of import proplot; print(proplot.version)
here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
DiscreteNorm does not support set_under/set_over colormap ...
[Description of the bug or feature.] Error when using boudary normalization for colormap. Steps to reproduce A "Minimal, Complete and ...
Read more >DiscreteNorm — ProPlot documentation - Read the Docs
This normalizer makes sure that levels always span the full range of colors in the colormap, whether extend is set to 'min' ,...
Read more >python - how to extract a subset of a colormap as a new ...
I'm interested to plot my data using the in-between colors. I think ppl use it quite often but I was searching over internet...
Read more >Colormap Normalization — Matplotlib 3.6.2 documentation
Matplotlib does this mapping in two steps, with a normalization from the input data to [0, 1] occurring first, and then mapping onto...
Read more >Control Colormap Limits - MATLAB & Simulink - MathWorks
Set the limits for scaling your data to a colormap. ... to values that are outside the range of C , so those...
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 FreeTop 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
Top GitHub Comments
@lukelbd Hi, luke. It’s ok now. Thanks for developing such an effective package!
Sorry I couldn’t get to this sooner, but I finally figured it out (see https://github.com/lukelbd/proplot/commit/f23ff70d54ffa668212e65c1d80ede3a310f5518). This was actually two separate bugs:
plot.Colormap()
automatically translates native matplotlib colormaps to proplot’s special colormap subclassesplot.colors.LinearSegmentedColormap
andplot.colors.ListedColormap
. However when doing this, proplot failed to copy the “extreme” color values.plot.DiscreteNorm()
failed to account for the possibility that there is a discrete transition between the minimum/maximum colors “within” the colormap range (colormap coordinates0
and1
) and the out of bounds colors (coordianates0 - eps
and1 + eps
). Now it takes this into account.Here’s your example on master (can be installed with
pip install git+https://github.com/lukelbd/proplot
):