-
Notifications
You must be signed in to change notification settings - Fork 102
Closed
Labels
Description
[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.