Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The out-of-bounds colors can be set using the <code>set_over</code> and <code>set_under</code> methods of the colormap; see <a href="http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.Colormap.set_over" rel="noreferrer">the documentation</a>. You'll need to specify these values when you create your colormap. I don't see any matplotlibrc setting to set the default for this, though. You might also want to ask on the matplotlib mailing list.</p> <p>Edit: I see what is going on. The white area you describe is not beyond the limits of the color range. It is simply the blank background of the axes. Because you are only plotting certain levels, any levels outside that range will not be plotted at all, leaving those areas blank. To get what you want, do this:</p> <pre><code>cs = pyplot.contourf(x,y,z,levels=np.arange(50, 220, 20), cmap=pyplot.cm.jet, extend="both") cs.cmap.set_under('k') cs.set_clim(50, 210) cb = pyplot.colorbar(cs) </code></pre> <p>The "extend" argument is the key; it tells contourf to go ahead and plot all contours, but collapse all outside the given range into "too big" and "too small" categories. The <code>cs.set_clim</code> call is necessary to work around an oddity I discovered in contourf while debugging this; for some reason when you use <code>extend</code>, it manipulates the data limits, so we need to reset them back to what we want them to be.</p> <p>Also, just as a matter of style, you shouldn't be doing things like <code>Colormap.set_under(cmap,color='k')</code>. This is calling the class method and explicitly passing the instance in, which is an odd way to do it. Just do <code>cmap.set_under(color="k")</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload