我有一个包含多列的热图图,如下所示:

这几乎就是我想要的。我使用imshow来做这件事,绘制代码非常简单,数据是一个二维numpy数组:
plt.imshow(data, cmap="hot",
vmin=0.0, vmax=1.0, aspect='auto',
interpolation='nearest')
plt.colorbar()
plt.show()不过,理想情况下,此头图中的列应该分组(或拆分),因为它们代表相关的事物。有没有什么简单的方法可以创建此图的版本,例如,我可以将列0-4、5-10和11-22分成不同的块,而不重复颜色条或yaxis标签,但每组列都有可能具有唯一的标签?
理想情况下,我想要一个看起来像( ascii艺术)的图:
0 +---+ +-------+ +-------------+ +-+ 1.0
| | | | | | | |
500 | | | | | | | |
| | | | | | | |
1000+---+ +-------+ +-------------+ +-+ 0.0
L1 Label2 Label3 有什么想法吗?
发布于 2018-01-08 04:31:36
您可以轻松地对data数组using standard numpy array notation进行切片。
在此之后,只需创建具有正确几何形状的轴。You could use Gridspec,或者看起来更简单的plt.subplots()版本。
data = np.random.random(size=(1000,22))
fig, axs = plt.subplots(1,3,sharey=True,gridspec_kw={'width_ratios':[5,6,12]})
a1 = axs[0].imshow(data[:,:5], cmap="hot",
vmin=0.0, vmax=1.0, aspect='auto',
interpolation='nearest')
a2 = axs[1].imshow(data[:,5:10], cmap="hot",
vmin=0.0, vmax=1.0, aspect='auto',
interpolation='nearest')
a3 = axs[2].imshow(data[:,11:], cmap="hot",
vmin=0.0, vmax=1.0, aspect='auto',
interpolation='nearest')
for ax,l in zip(axs,['Label 1','Label 2','Label 3']):
ax.set_xticklabels([])
ax.set_xlabel(l)
plt.colorbar(a1)
plt.show()

https://stackoverflow.com/questions/48140977
复制相似问题