1

I need to plot 2D "heat map" using python using data from my file. My file has 3 columns x,y, value. x goes from 1 to 199 and y from 1 to 49. I've managed to use code from here: Make a 2D pixel plot with matplotlib but my area is rectangular and I need it to be "lying" rectangle, but code above makes it "standing" rectangle.

Any way how to rotate it by 90 degrees anti-clockwise or transpose the data? I'm very new to python and all the solutions I've found doesn't work...

Here's my code that produces "standing" rectangle:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

x,y,temp = np.loadtxt('snorm000990987662298').T 
nrows, ncols = 199, 49
grid = temp.reshape((nrows, ncols))

plt.imshow(grid,  cmap=cm.gist_gray)
plt.show()
Community
  • 1
  • 1
Martin
  • 13
  • 4

1 Answers1

0

Try using numpy.transpose:

grid = np.transpose(grid)
plt.imshow(grid, cmap=cm.gist_gray)
plt.show()
Jeff
  • 51
  • 3
  • Nice, this works thanks, its "lying" rectangle, now i need to reverse the grid in y axis because its upside down... – Martin Mar 04 '16 at 18:35
  • Ah. What you want is then probably [`numpy.rot90`](http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.rot90.html#numpy.rot90): `grid = np.rot90(grid)`. See also [`numpy.flipud`](http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.flipud.html) and [`numpy.fliplr`](http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.fliplr.html). – Jeff Mar 04 '16 at 20:16
  • I've flipped the y-axis :). But thanks your solution works as well. – Martin Mar 04 '16 at 21:43