Matplotlib.axes.Axes.xaxis_inverted() in Python
Last Updated :
19 Apr, 2020
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.xaxis_inverted() Function
The Axes.xaxis_inverted() function in axes module of matplotlib library return whether the x-axis is inverted or not.
Syntax: Axes.xaxis_inverted(self)
Parameters: This method does not accepts any parameters.
Returns:This method return whether the x-axis is inverted or not.
Below examples illustrate the matplotlib.axes.Axes.xaxis_inverted() function in matplotlib.axes:
Example 1:
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_xaxis()
ax.set_title('matplotlib.axes.Axes.xaxis_inverted()\
Example\n',
fontsize = 14 , fontweight = 'bold' )
x = ax.xaxis_inverted()
ans = "No"
if x:
ans = "Yes"
ax.text( 2.2 , 1.02 , "X-axis is inverted ? : " + ans,
style = 'italic' , fontsize = 12 )
plt.show()
|
Output:
Example 2:
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_xaxis()
ax.set_xlabel( 'Performance' )
x = ax.xaxis_inverted()
ans = "No"
if x:
ans = "Yes"
ax.set_title('matplotlib.axes.Axes.xaxis_inverted()\
Example\n',
fontsize = 14 , fontweight = 'bold' )
ax.text( 6 , 4.75 , "X-axis is inverted ? : " + ans,
style = 'italic' , fontsize = 12 )
plt.show()
|
Output:
Share your thoughts in the comments
Please Login to comment...