python - Heat Map Annotation with text -
i trying plot heat map. col[2]
, col[3]
, col[1]
x
, y
, z
axis. want annotate cells. later trying use col[0]
labels on axis (for human readable). valuable suggestions appreciated. !!
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 heatmap
import numpy np import matplotlib.pyplot 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 including annotations
program 2
import matplotlib.pyplot plt import numpy np data = np.loadtxt('inputfile', unpack=true, dtype='str, int, float, float') heatmap = plt.pcolor(data) y in range(data.shape[2]): 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
requires 2d z
array, have 1d array.
Comments
Post a Comment