Home > Backend Development > Python Tutorial > How to Create a Logarithmic Axis Plot in Matplotlib?

How to Create a Logarithmic Axis Plot in Matplotlib?

Mary-Kate Olsen
Release: 2024-11-05 06:58:02
Original
856 people have browsed it

How to Create a Logarithmic Axis Plot in Matplotlib?

How to Plot Logarithmic Axes in Matplotlib

In matplotlib, you can easily create a graph with one or both axes in logarithmic scale. To plot a graph with one logarithmic axis, you can use the Axes.set_yscale method.

Here is an example of how to plot a graph with a logarithmic y-axis:

import matplotlib.pyplot as plt
a = [pow(10, i) for i in range(10)]  # exponential
fig = plt.figure()
ax = fig.add_subplot(2, 1, 1)

line, = ax.plot(a, color='blue', lw=2)

ax.set_yscale('log')

plt.show()
Copy after login

You can change 'log' to 'linear' to switch back to a linear scale.

Here is the result of the code:

[Image of the result chart]

The above is the detailed content of How to Create a Logarithmic Axis Plot in Matplotlib?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template