Matplotlib热图故障

时间:2018-10-25 15:14:24

标签: matplotlib heatmap

这个简单的代码应该产生平滑的热图:

X = [[1,2],[3,4],[5,6]]
plt.imshow(X)
plt.show() 

但是我得到的是这些色块:

enter image description here

我在pycharm和jupyter中都对其进行了测试,并且都一样。 我正在使用python 3.5,使用pip安装了matplotlib。 有人请帮忙。

1 个答案:

答案 0 :(得分:0)

imshow可以使用几种不同的插值方法生成热图。默认显示为None,因此您会看到上面看到的“块”。诸如bilinear之类的其他方法将执行平滑插值。还有许多其他选项。有关不同方法的完整概述,请参见here

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(ncols=2)

X = [[1,2],[3,4],[5,6]]
ax1.imshow(X, interpolation='None')
ax2.imshow(X, interpolation='bilinear')

ax1.set_title('None')
ax2.set_title('bilinear')

plt.show()

enter image description here