I want to plot a graph with one logarithmic axis using matplotlib.
Sample program:
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)
plt.show()
There are a few methods given on this page (semilogx, semilogy, loglog) but they all do the same thing under the hood, which is to call
set_xscale('log')
(for x-axis) andset_yscale('log')
(for y-axis). Moreover,plt.yscale
/plt.scale
are functions in the state-machine, which make calls toset_yscale
/set_xscale
on the current Axes objects. Even for bar-charts (and histograms too since they are just bar-charts), thelog=True
parameter makes calls toset_yscale('log')
/set_xscale('log')
depending on the bar orientation.So it doesn't matter which one you use, they all end up calling the same method anyway. By the way, on top of being able to choose the base of the log, you can also set minor tick locations in the same function call (using
subs
kwarg).