how to check if y axis is inverted matplotlib

Solutions on MaxInterview for how to check if y axis is inverted matplotlib by the best coders in the world

showing results for - "how to check if y axis is inverted matplotlib"
Mehtab
07 Apr 2018
1import matplotlib.pyplot as plt
2
3# ('gca' stands for get current axes)
4
5# To check whether the y axis is inverted:
6plt.gca().yaxis_inverted()
7
8# To check whether the x axis is inverted:
9plt.gca().xaxis_inverted()
10
11"""
12
13Both functions return True if their axes are inverted.
14- The y axis is inverted if the values are increasing downwards.
15- The x axis is inverted if the values are increasing leftwards.
16
17"""
18
19# To flip the y axis:
20plt.gca().invert_yaxis()
21
22#To flip the x axis:
23plt.gca().invert_xaxis()
24
25"""
26
27When plotting the equation 'y=-x' the y axis tends to flip for some
28reason, so to overcome this and keep the y axis non-inverted you can
29check whether the axis is inverted and if True re-flip it the right way
30round:
31
32"""
33
34if plt.gca().yaxis_inverted():
35    plt.gca().invert_yaxis()
36