The x and y axes for Matplotlib imshow ()

I am using pyplot with matplotlib and I would like to display some data as an image. When I use imshow() , the data is upside down from the way I want to view it. How would I switch the x and y axes, either using imshow() or into a numpy array before sending it to imshow() ?

(i.e. I want the horizontal axis to be vertical)

I tried using origin='upper' and origin='lower' in the imshow() command, but that just changes one axis instead of switching it

I also tried using reshape for the data, but the order reshape

+8
numpy matplotlib image
source share
1 answer

To close the question -

You need to transfer the numpy array before passing it to matplotlib :

 >>> a array([[0, 1], [2, 3]]) >>> a=aT >>> a array([[0, 2], [1, 3]]) 

Thus, using plt , this should be simple:

 plt.imshow(aT) 
+12
source share

All Articles