|
From: Luke L. <dur...@gm...> - 2015-02-17 22:24:16
|
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 the color bar documentation at http://matplotlib.org/examples/api/colorbar_only.html as a guide. Maybe I'm doing something wrong or the example is slightly off? I'm using matplotlib 1.4.0. You can see examples of the images I'm generating here: - https://github.com/matplotlib/matplotlib/issues/4117 It's been suggested to on the above tracker to use imshow. However, that doesn't address the issue I'm having using PolyCollection. In addition, I'm not sure how to translate my example below so that it will work with imshow because I'm trying to plot a 2D slice of a 3D array. The code in question is below. Sorry for not including re-usable array data in the example. My specific case is with a large 3D array that has several thousands vertices, etc. Again, you can see the image examples here: - https://github.com/matplotlib/matplotlib/issues/4117 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() Thanks, Luke |