Python | Logit Scale in Plotting

In this article, we are going to learn how to change y-axis scale from linear to logit in Python plot using matplotlib?
Submitted by Anuj Singh, on August 20, 2020

When we need to plot data in logit form, then we can use an inbuilt defined function matplotlib.pyplot.yscale('logit').

We have illustrated the usage using the below example and also compared it with the linear scale in the subplot.

Illustrations:

Python | Logit Scale in Plotting (1)

Python | Logit Scale in Plotting (2)

Python code for logit scale in plotting

import matplotlib.pyplot as plt
import numpy as np

y = np.random.normal(loc=0.5, scale=0.4, size=1000)
y = y[(y > 0) & (y < 1)]
y.sort()
x = np.arange(len(y))

plt.figure()
plt.plot(x, y)
plt.title('linear scale')
plt.grid(True)
plt.show()

plt.figure()
plt.plot(x, y)
plt.yscale('logit')
plt.title('logit scale')
plt.grid(True)
plt.show()

Output:

Output is as Figure


Comments and Discussions!

Load comments ↻





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