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()
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!