using matplotlib 0.99, I have a problem with colorbars, which is illustrated
by the following code:
from matplotlib import ticker
import numpy as np
a = np.arange(676).reshape((26,26))
x = y = np.arange(26)
colorMap = mpl.cm.get_cmap('jet', 10)
colorNorm = mpl.colors.Normalize(vmin=0, vmax=400,clip=True)
plot = contourf(x,y,a,10,cmap=colorMap,norm=colorNorm, \
cb = colorbar(plot,orientation='horizontal',cmap=colorMap,norm=colorNorm, \
So I have data ranging from 0 up to say 675. I want to create a contour plot,
but the colorbar should only go up to 400, and all values higher than that
should be shown in the color of the maximum value 400, which is working
However, the colorbar does not go from 0 to 400, but rather from 0 to 675:
In : cb._boundaries
array([ -6.75000000e-04, 7.50000000e+01, 1.50000000e+02,
2.25000000e+02, 3.00000000e+02, 3.75000000e+02,
4.50000000e+02, 5.25000000e+02, 6.00000000e+02,
The colors shown are correct, but the colorbar looks ugly, because two
of it are filled with the color of the maximum value.
According to the documentation
If clip is True and the given value falls outside the range, the
value will be 0 or 1, whichever is closer.
So my question is: What do I need to do so that the colorbar actually has
range as specified by my colorNorm?
Thanks for your help,
From: Friedrich Romstedt <friedrichromstedt@gm...> - 2010-04-15 19:56:47
2010/4/14 Andreas Hilboll <lists@...>:
> So my question is: What do I need to do so that the colorbar actually has
> range as specified by my colorNorm?
We had a beautiful discussion about this recently under "Making a
data-driven colormap", maybe this helps.