Skip to content

Colormap set_under and set_over have no effect on color bar for PolyCollection #4117

Closed
@durden

Description

@durden

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

plot_with_mask

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions