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
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to