Python | Inverting Axis in Python Matplotlib

In this article, we are going to invert the axis and illustrate through the subplot example.
Submitted by Anuj Singh, on July 31, 2020

It helps us in reversing the scale, from higher values at origin and lowers while going far from the axis.

Inverting Axis in Python Matplotlib (1)

Inverting Axis in Python Matplotlib (2)

Inverting Axis in Python Matplotlib (3)

Python code for inverting axis in python matplotlib

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.01, 5.0, 0.13)
s = np.exp(-t)

plt.figure()
plt.plot(t, s, 'o', color='purple')
plt.xlabel('Time')
plt.ylabel('Potential')
plt.title('Normal')
plt.grid()
plt.show()

plt.figure()
plt.plot(t, s, 'o', color='purple')
plt.xlim(5, 0)  # decreasing time
plt.xlabel('Time')
plt.ylabel('Potential')
plt.title('Inverted')
plt.grid()
plt.show()

plt.figure()
plt.suptitle('Inversion of Axis')
plt.subplot(121)
plt.plot(t, s, 'o', color='purple')
plt.xlabel('Time')
plt.ylabel('Potential')
plt.title('Normal')
plt.grid()

plt.subplot(122)
plt.plot(t, s, 'o', color='purple')
plt.xlim(5, 0)  # decreasing time
plt.xlabel('Time')
plt.ylabel('Potential')
plt.title('Inverted')
plt.grid()
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.