Closed
Description
I'm trying to control the over and under colors of a color bar with set_under
and set_over
on a ListedColormap
object. I do not see the colors change, but I do see the arrows added to the color bar.
For example, the following code mostly works but the calls to set_under
and set_over
seem to have no effect. I'm trying to use this color bar documentation as a guide. Maybe I'm doing something wrong or the example is slightly off?
I'm using matplotlib 1.4.0.
import numpy
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
vertices = numpy.load('vertices.npy')
array = numpy.load('array.npy')
# Take 2d slice out of 3D array
slice_ = array[:, :, 0:1].flatten(order='F')
fig, ax = plt.subplots()
poly = PolyCollection(vertices, array=slice_, edgecolors='black', linewidth=.25)
cm = mpl.colors.ListedColormap([(1.0, 0.0, 0.0), (.2, .5, .2)])
cm.set_under('0.75')
cm.set_over('DarkViolet')
poly.set_cmap(cm)
bounds = [.1, .4, .6]
norm = mpl.colors.BoundaryNorm(bounds, cm.N)
bounds = [0.0] + bounds + [1.0]
fig.colorbar(poly, ax=ax, orientation='vertical', boundaries=bounds, norm=norm,
extend='both')
ax.add_collection(poly, autolim=True)
ax.autoscale_view()
plt.show()
Metadata
Metadata
Assignees
Labels
No labels