Open In App

Matplotlib.axes.Axes.invert_yaxis() in Python

Last Updated : 19 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.invert_yaxis() Function

The Axes.invert_yaxis() function in axes module of matplotlib library is used to invert the y-axis.

Syntax: Axes.invert_yaxis(self)

Parameters: This method does not accepts any parameters.

Returns:This method does not returns any value.

Below examples illustrate the matplotlib.axes.Axes.invert_yaxis() function in matplotlib.axes:

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
       
X = np.arange(-20, 20, 0.5)
Y = np.arange(-20, 20, 0.5)
U, V = np.meshgrid(X, Y)
   
fig, ax = plt.subplots()
ax.quiver(X, Y, U, V)
w = ax.invert_yaxis()
ax.set_title('matplotlib.axes.Axes.invert_yaxis() \
Example', fontsize = 14, fontweight ='bold')
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
       
x = np.linspace(0, 200, 10)
yy = np.transpose([2 * np.sin(x + phi) for phi in x])
   
fig, ax = plt.subplots()
ax.plot(yy)
w = ax.invert_yaxis()
ax.set_title('matplotlib.axes.Axes.invert_yaxis()\
 Example', fontsize = 14, fontweight ='bold')
plt.show()


Output:

python-matplotlib-axes-inverty



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads