白色pcolor介绍白色酒吧

时间:2015-09-12 20:31:50

标签: python matplotlib

我有以下脚本

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(24,7)
heatmap = plt.pcolor(data)
plt.show()

这会导致此图片

enter image description here

如何删除顶部的白条?

3 个答案:

答案 0 :(得分:3)

当您使用pcolor时,您必须手动设置x和y限制。

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(24,7)
heatmap = plt.pcolor(data)
plt.ylim(0, 24)
plt.show()

答案 1 :(得分:3)

我假设您的矩阵不是锯齿状矩阵:

import matplotlib.pyplot as plt
import numpy as np

data = np.random.rand(24,7)
nrow, ncol = data.shape
heatmap = plt.pcolor(data)
# put the major ticks
heatmap.axes.set_xticks(np.arange(ncol), minor=False)
heatmap.axes.set_yticks(np.arange(nrow), minor=False)
heatmap.axes.set_xlim(0,ncol) # Assuming a non jagged matrix
heatmap.axes.set_ylim(0,nrow)
plt.show()

enter image description here

答案 2 :(得分:1)

只是简单的改变。 np.random.rand(24,7)替换为np.random.rand(25,7)

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(25,7)
heatmap = plt.pcolor(data)
plt.show()

输出: enter image description here

或添加轴类似 plt.axis([0,7,0,24])

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(24,7)
heatmap = plt.pcolor(data)
plt.axis([0,7,0,24])
plt.show()

输出: enter image description here