我正在尝试修改现有的
python代码,使用np.histogram2d绘制值的热图.我正在绘制其中的几个,我希望y轴和颜色范围在它们之间具有可比性.我找到了手动设置y_limit的方法,但现在我想要修复颜色范围.以下代码段:
hist,xedges,yedges = np.histogram2d(x,y, bins=[20, 50], range=[ [0, 100.0], [0, y_limit] ])
# draw the plot
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1] ]
im = ax.imshow(hist.T,extent=extent,interpolation='nearest',origin='lower', aspect='auto')
# colormap, colorbar, labels, ect.
im.set_cmap('gist_heat_r')
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", "5%", pad="3%")
ax.figure.colorbar(im, cax=cax)
ax.set_title(d['name'] + ' foo')
ax.set_xlabel("bar")
ax.set_ylabel("coverage")
并且示例显示了不同的颜色范围,其中一个从0到2800以上,另一个从0到2400以上.我希望能够将颜色范围设置为固定的最大值,例如:两者都是3000.有任何想法吗?
编辑:使用vmin和vmax解决.