HomeLanguagesMatplotlib.axes.Axes.yaxis_inverted() in Python

Matplotlib.axes.Axes.yaxis_inverted() in Python

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.yaxis_inverted() Function

The Axes.yaxis_inverted() function in axes module of matplotlib library return whether the y-axis is inverted or not.

Syntax: Axes.yaxis_inverted(self)

Parameters: This method does not accepts any parameters.

Returns:This method return whether the y-axis is inverted or not.

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

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
   
fig, ax = plt.subplots()
   
ax.axvspan(1.5, 2.5, facecolor ='g', alpha = 0.7)
ax.invert_yaxis()
  
ax.set_title('matplotlib.axes.Axes.yaxis_inverted() \
Example\n',
             fontsize = 14, fontweight ='bold')
x = ax.yaxis_inverted()
ans ="No"
if x:
    ans ="Yes"
ax.text(1.8, -0.02, "Y-axis is inverted ? : " + ans,
        style ='italic', fontsize = 12)
  
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
   
np.random.seed(19680801)
plt.rcdefaults()
fig, ax = plt.subplots()
  
people = ('Geek1', 'Geek2', 'Geek3',
          'Geek4', 'Geek5')
  
y_pos = np.arange(len(people))
performance = 3 + 4.5 * np.random.rand(len(people))**2
error = np.random.rand(len(people))
  
ax.barh(y_pos, performance, xerr = error,
        align ='center', color ="green")
ax.set_yticks(y_pos)
ax.set_yticklabels(people)
  
ax.invert_yaxis()  
ax.set_xlabel('Performance')
x = ax.yaxis_inverted()
ans ="No"
if x:
    ans ="Yes"
      
ax.set_title('matplotlib.axes.Axes.yaxis_inverted() \
Example\n',
             fontsize = 14, fontweight ='bold')
ax.text(3, -0.75, "Y-axis is inverted ? : " + ans, 
        style ='italic', fontsize = 12)
  
plt.show()


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32726 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7104 POSTS0 COMMENTS
Nicole Veronica
12241 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12328 POSTS0 COMMENTS
Shaida Kate Naidoo
7219 POSTS0 COMMENTS
Ted Musemwa
7477 POSTS0 COMMENTS
Thapelo Manthata
7200 POSTS0 COMMENTS
Umr Jansen
7176 POSTS0 COMMENTS