RISEBY
您的线未在对数刻度图上拉伸的原因是因为顶部和底部的点之间没有点。log plot不弯曲线,只是将点放在不同的比例上,它们之间的线仍然是直的。为了改变这一点,我们在点之间添加了更多的点。结果会变得弯曲。import matplotlibimport matplotlib.pyplot as pltimport numpy as npfrom matplotlib.ticker import ScalarFormatter# Data for plottingt = [0.0, 62.5, 125.0, 187.5, 250, 312.5, 375, 437.5, 500]s = [0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1]def extendlist(l): master = [] for i in range(len(l)-1): x = np.linspace(l[i], l[i+1], 50) master.extend(x) return mastert = extendlist(t)s = extendlist(s)fig, ax = plt.subplots()ax.semilogy(t, s)ax.set(xlabel='x axis', ylabel='y axis', title='Stuff')plt.xlim((0,500))plt.ylim((0.001, 1))plt.show()这将生成您在纸上绘制的图形。
忽然笑
你可以使用interp1dimport matplotlib.pyplot as pltimport numpy as npfrom scipy.interpolate import interp1dt = [0.0, 62.5, 125.0, 187.5, 250, 312.5, 375, 437.5, 500]s = [0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1]tnew = np.linspace(0, 500, num=1001, endpoint=True)f = interp1d(t, s)plt.semilogy(tnew, f(tnew))plt.ylim((0.001, 1))plt.show()