2 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個贊
您的線未在對數(shù)刻度圖上拉伸的原因是因?yàn)轫敳亢偷撞康狞c(diǎn)之間沒有點(diǎn)。log plot不彎曲線,只是將點(diǎn)放在不同的比例上,它們之間的線仍然是直的。
為了改變這一點(diǎn),我們在點(diǎn)之間添加了更多的點(diǎn)。結(jié)果會變得彎曲。
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter
# Data for plotting
t = [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 master
t = 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()
這將生成您在紙上繪制的圖形。

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個贊
你可以使用interp1d
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d
t = [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()
添加回答
舉報