【发布时间】:2015-09-21 00:54:53
【问题描述】:
我正在尝试修改现有的一段 python 代码,该代码使用np.histogram2d 绘制值的热图。我正在绘制其中的几个,我希望 y 轴和颜色范围在它们之间具有可比性。我找到了手动设置y_limit 的方法,但现在我希望颜色范围也可以修复。代码如下:sn-p:
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 解决。
【问题讨论】:
-
为什么要删除
aspect='auto'? -
啊啊,明白了!这就是问题所在!
标签: python numpy histogram2d