Syntax error Plot yscale class linear, log, logit and symlog by name in Matplotlib?

Plot yscale class linear, log, logit and symlog by name in Matplotlib?



To plot yscale with class by name, we can take the following steps

  • Set the figure size and adjust the padding between and around the subplots.
  • Create y data points using numpy.
  • Create x data points using numpy.
  • Add a subplot to the current figure at index 1.
  • Plot x and y data points using plot() method.
  • For linear class by name, use yscale("linear") method.
  • Set the title of the current subplot.Repeat the steps from 4 to 5 with different indices, yscale() class by name, and title of the plot.
  • To display the figure, use show() method.

Example

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
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))

# linear
plt.subplot(221)
plt.plot(x, y)
plt.yscale('linear')
plt.title('linear')

# log
plt.subplot(222)
plt.plot(x, y)
plt.yscale('log')
plt.title('log')

# symmetric log
plt.subplot(223)
plt.plot(x, y - y.mean())
plt.yscale('symlog', linthreshy=0.01)
plt.title('symlog')

# logit
plt.subplot(224)
plt.plot(x, y)
plt.yscale('logit')
plt.title('logit')
plt.show()

Output

Updated on: 2021-06-02T08:17:35+05:30

522 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements