我正在尝试绘制这个heat map。 Col[3]
,Col[1]
和x
为y
,z
和Col[0]
轴。我想注释细胞。后来我尝试使用0839d22dae7b 1952062 73.780274 19.990045
a43cf52552c7 227842 73.780300 19.990028
c9bb69ddffb8 1039483 73.780291 19.990085
d25da834c045 1109172 73.780021 19.990063
a4dbf9179594 586820 73.780103 19.990226
b11c617da1d9 2793875 73.780131 19.990324
31dc8159727a 1350028 73.780282 19.990195
92bfaf82dbe1 579988 73.780214 19.990315
46f9c8db4a74 2669870 73.780162 19.990332
作为轴上的标签(用于人类可读)。值得赞赏的宝贵建议。谢谢!!
输入
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('input', unpack=True, dtype='str, float, float')
x = data[1]
y = data[2]
#hist = np.hist2d(x,y, bins=40)
plt.hist2d(x, y, bins=10)
#plt.pcolor(hist)
plt.colorbar()
plt.grid()
plt.show()
仅用于热图的程序1
import matplotlib.pyplot as plt
import numpy as np
data = np.loadtxt('inputfile', unpack=True, dtype='str, int, float, float')
heatmap = plt.pcolor(data)
for y in range(data.shape[2]):
for x in range(data.shape[3]):
plt.text(x + 0.5, y + 0.5, '%.4f' % data[y, x],
horizontalalignment='center',
verticalalignment='center',
)
plt.colorbar(heatmap)
plt.show()
以下程序用于包含注释
计划2
Traceback (most recent call last):
File "heat4.py", line 5, in <module>
heatmap = plt.pcolor(data)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2928, in pcolor
ret = ax.pcolor(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 7545, in pcolor
X, Y, C = self._pcolorargs('pcolor', *args, allmatch=False)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 7341, in _pcolorargs
numRows, numCols = C.shape
AttributeError: 'list' object has no attribute 'shape
错误
printf("Executing the command: %s\n", cmd);
&#39;
答案 0 :(得分:0)
pcolor
需要2D z
数组,您只有一维数组。