简体   繁体   English

带文字的热图注释

[英]Heat Map Annotation with text

I am trying to plot this heat map . 我正在尝试绘制这张热图 Col[2] , Col[3] and Col[1] are x , y and z axis. Col[2]Col[3]Col[1]xyz轴。 I want to annotate the cells. 我想注释单元格。 Later I am trying to use Col[0] as labels on axis (for human readable). 稍后,我尝试将Col[0]用作轴上的标签(便于人类阅读)。 Valuable suggestions are appreciated. 感谢您提出宝贵的建议。 Thanks !! 谢谢 !!

Input 输入

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 

Program 1 for only heatmap 程序1仅用于热图

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()

The below program is for including annotations 以下程序用于包含注释

Program 2 程序2

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()

Error 错误

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

'

pcolor需要2D z数组,而只有1D数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM