import numpy as np
from matplotlib import pyplot as plt
x = np.arange(0, 100, 0.5)
y = 2 * x ** 3
plt.loglog(x, y)
plt.grid(True, which='both', ls='--')
plt.figure()
plt.plot(x, y)
plt.yscale('log')
plt.grid(True, which='both', ls='--')
plt.figure()
plt.plot(x,y)
plt.xscale('log')
plt.grid(True, which='both', ls='--')
plt.figure()
plt.plot(x,y)
plt.grid(True, which='both', ls='--')
plt.figure()
plt.plot(x, y)
plt.yscale('log')
plt.grid(True, which='major', ls='--')
plt.figure()
plt.plot(x, y)
plt.yscale('log')
plt.grid(True, which='minor', ls='--')
最终的结果为:
有用的代码
from matplotlib.ticker import (AutoMinorLocator, MultipleLocator, LogLocator)
y_major = LogLocator(base=10.0, numticks=5)
ax1.yaxis.set_major_locator(y_major)