[英]Custom colorbar with quiver plot in matplotlib
I'm trying to produce a quiver plot, vector lengths range from 0. to 15., and I'd like to use a grey colormap but starting from, say, half-range, such that 0. is already grey and 15. is black. 我正在尝试生成一个颤抖图,矢量长度范围从0.到15.,并且我想使用灰色的颜色图,但是从例如半范围开始,例如0.已经是灰色和15。是黑色的。 What I've done so far is:
到目前为止,我所做的是:
cmap = cm.get_cmap('Greys', 10)
norm = matplotlib.colors.Normalize(vmin=-5.,vmax=15.,clip=False)
Q = ax.quiver(xi, yi, zix, ziy, lengths * 1000., units='inches', width=0.008, headwidth=6, headlength=7, scale=5,
scale_units='inches',cmap=cmap, norm=norm)
cb = plt.colorbar(Q, cax=ax3, ticks=[0.0, 3.0, 6.0, 9.0, 12.0, 15.0], format='%.1f', norm=norm)
The color range is correct but the whole colormap is shown in the colorbar, ie starting from the white color. 颜色范围是正确的,但是整个颜色图会显示在颜色栏中,即从白色开始。 What am I missing?
我想念什么?
The "Greys" colormap starts at white and goes to black. “灰色”颜色图从白色开始,然后变为黑色。 Due to your normalization -5 is white and 15 is black.
由于标准化,-5为白色,而15为黑色。
What you seem to really want is a normalization of vmin=0,vmax=15.
您似乎真正想要的是对
vmin=0,vmax=15.
的归一化vmin=0,vmax=15.
and a colormap which starts with a grey color already: 和已经以灰色开头的颜色图:
import matplotlib.colors
norm = matplotlib.colors.Normalize(vmin=0,vmax=15.,clip=False)
cmap = matplotlib.colors.ListedColormap(plt.cm.Greys(np.linspace(0.25,1,10)), "name")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.