【发布时间】:2016-07-20 12:40:41
【问题描述】:
到目前为止,我正在制作一个看起来像这样的情节:
我正在使用以下代码:
import matplotlib.pyplot as plt
import numpy as np
column_labels = ['A','B']
row_labels = ['A','B']
data = np.random.rand(2,2)
print(type(data))
data = np.array([[1, 0.232], [0.119, 1]])
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=plt.cm.Blues)
# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[0])+0.5, minor=False)
ax.set_yticks(np.arange(data.shape[1])+0.5, minor=False)
# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()
ax.set_xticklabels(row_labels, minor=False)
ax.set_yticklabels(column_labels, minor=False)
plt.show()
我想要得到的是这样的:
我可以在哪里看到颜色条以及它们上的单元格的值。我需要在我的代码中添加什么来获得这些?
谢谢
【问题讨论】:
-
与单元格上的文本有些相关:stackoverflow.com/questions/21712047/…
-
对于彩条,你试过
fig.colorbar(heatmap)吗?
标签: python matplotlib heatmap