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!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.