Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invert an axis in a matplotlib grafic

How can I invert the y_axis? Z is a np.array.Thank you

Z=TempLake   X,Y=np.meshgrid(range(Z.shape[0]+1),range(Z.shape[1]+1))  im = plt.pcolormesh(X,Y,Z.transpose(), cmap='hot')  plt.colorbar(im, orientation='horizontal')  plt.show()  

I have this:

enter image description here

I need this: enter image description here

like image 805
user1419224 Avatar asked Aug 02 '12 12:08

user1419224


People also ask

How do I invert axis in Matplotlib?

In Matplotlib we can reverse axes of a graph using multiple methods. Most common method is by using invert_xaxis() and invert_yaxis() for the axes objects. Other than that we can also use xlim() and ylim(), and axis() methods for the pyplot object.

How do you reverse axis in Seaborn?

Looks like ax. invert_yaxis() solves it.

How do you reverse a histogram in Python?

To get a reverse-order cumulative histogram in Matplotlib, we can use cumulative = -1 in the hist() method. Set the figure size and adjust the padding between and around the subplots.


1 Answers

As @Chris said, this can be done with:

ax = plt.gca() ax.invert_yaxis() 

Before the 'plt.show()'.

like image 146
pelson Avatar answered Sep 20 '22 08:09

pelson