1

假设我们有这些数据:

import matplotlib.pyplot as plt
import numpy as np

Y = np.array([500.,  1000.,  1500.,  2000.,  2500.,  3000.,  3500.,  4000.,
        4500.,  5000.,  5500.,  6000.,  6500.,  7000.,  7500.,  8000.,
        8500.,  8999.])
P = np.array([0.35719454,  1.33640227,  3.6250187 ,  4.6098672 ,  3.07393609,
        3.37146857,  3.63601765,  4.22452476,  3.89485839,  4.1829315 ,
        4.02657142,  4.17620968,  4.06966698,  4.18009466,  4.16220121,
        4.60149918,  4.31294132,  3.94933813])

plt.plot(Y,P)
plt.show()

我怎样才能使它平滑一点,同时在 x 轴上表示的每个元素上绘制一个标记?有没有办法做到这一点?

4

1 回答 1

3

这是你想要的?

import matplotlib.pyplot as plt
import numpy as np

Y = np.array([500.,  1000.,  1500.,  2000.,  2500.,  3000.,  3500.,  4000.,
        4500.,  5000.,  5500.,  6000.,  6500.,  7000.,  7500.,  8000.,
        8500.,  8999.])
P = np.array([0.35719454,  1.33640227,  3.6250187 ,  4.6098672 ,  3.07393609,
        3.37146857,  3.63601765,  4.22452476,  3.89485839,  4.1829315 ,
        4.02657142,  4.17620968,  4.06966698,  4.18009466,  4.16220121,
        4.60149918,  4.31294132,  3.94933813])

from scipy.interpolate import interp1d
f2 = interp1d(Y, P, kind='cubic')

xnew = np.linspace(min(Y), max(Y), 100) # you can change the 100 here to a smaller number if you want less 'smoothness'
plt.plot(Y,P,'o',xnew, f2(xnew),'--')

plt.show()
于 2013-05-28T17:13:56.210 回答