Thursday, September 4, 2025
HomeLanguagesHow to put the y-axis in logarithmic scale with Matplotlib ?

How to put the y-axis in logarithmic scale with Matplotlib ?

Axes’ in all plots using Matplotlib are linear by default, yscale() method of the matplotlib.pyplot library can be used to change the y-axis scale to logarithmic.

The method yscale() takes a single value as a parameter which is the type of conversion of the scale, to convert y-axes to logarithmic scale we pass the “log” keyword or the matplotlib.scale.LogScale class to the yscale method.

Syntax :  matplotlib.pyplot.yscale(value, **kwargs)

Parameters:

  • Value = { “linear”, “log”, “symlog”, “logit”, … }
  • **kwargs = Different keyword arguments are accepted, depending on the scale (matplotlib.scale.LinearScale, LogScale, SymmetricalLogScale, LogitScale)

Returns : Converts the y-axes to the given scale type. (Here we use the “log” scale type)

Linear Scale Example : 

Python3




import matplotlib.pyplot as plt
  
data = [10**i for i in range(4)]
plt.plot(data)


Output: 

Linear Scale

Logarithmic Scale Example : 

Python3




import matplotlib.pyplot as plt
  
data = [10**i for i in range(4)]
  
# convert y-axis to Logarithmic scale
plt.yscale("log")  
plt.plot(data)


Output: 

Logarithmic y-axis

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS