使用Python绘制热图

时间:2018-08-30 11:38:49

标签: python matplotlib plot charts

我想使用Python生成热图。 地图应该是这样的:

enter image description here 我有一个维度为(n,n)的numpy数组,每个“单元格”都包含一个特定值。该值越高,粉红色正方形应该越大。 如何使用matplotlib绘制此类图表?我还可以使用其他库吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试

n = 8
x = np.arange(n)
y = np.arange(n)
X, Y = np.meshgrid(x, y)
Z = np.random.randint(0, 800, (len(x), len(y)))
plt.figure()
plt.axes(aspect='equal')
plt.scatter(X+.5, Y+.5, Z, 'pink', marker='s')
plt.grid()
plt.xlim(0, n)
plt.ylim(0, n)
plt.tick_params(labelsize=0, length=0)

enter image description here