Python | Symmetric Log Scale for Y axis in Matplotlib

In this article, we are going to set y axis scale as symlog for mathematical data visualization.
Submitted by Anuj Singh, on August 14, 2020

When we need to plot data in symmetric logarithmic form, then we can use an inbuilt defined function matplotlib.pyplot.yscale('symlog'). We have illustrated the usage using the below example and also compared it with the linear scale in the subplot.

Illustration:

Symmetric Log Scale for Y axis (1)

Symmetric Log Scale for Y axis (2)

Python code for symmetric log scale for y axis in matplotlib

import numpy as np
import matplotlib.pyplot as plt

dt = 1 
x = np.arange(-50.0, 50.0, dt)
y = np.arange(0, 100.0, dt)

plt.figure()
plt.plot(x, y, '.', color='purple')
plt.title('Y Scale : Symlog')
plt.yscale('symlog')
plt.show()

y = np.exp(-x)
plt.figure()
plt.plot(x, y, '.', color='purple')
plt.title('YScale : Symlog')
plt.yscale('symlog')
plt.show()

Output:

Output is as Figure


Comments and Discussions!

Load comments ↻





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