如何在pcolormesh上绘制点或线?

时间:2019-05-13 10:18:59

标签: python matplotlib

我从科学数据中绘制了一个pcolormesh,我想绘制峰点,并最终绘制一条连接它们的线。数据中有18k点。我在python中执行以下操作:

meas = #the data I read from .json file
ex['x'] = np.array(meas['vc'])[:400]
y = np.array(meas['vrf_dc'])
ex['y'] = np.linspace(y.min(),y.max(), int(len(y)/400/2))
ex['z'] = np.array(meas['s'])[18000:].reshape(len(ex['y']), len(ex['x']))

fig, ax = plt.subplots()
ax.pcolormesh(ex['x'], ex['y'], ex['z'])

并得到这个:pcolormesh plot

我使用scipy.signal.find_peaks通过以下代码获得峰值:

peaks = []
for sweep in range(len(ex['y'])):
    peak, _ = find_peaks(ex['z'][sweep], height=20, distance=20)
    peaks += [peak]

并最终尝试在上图中绘制这些峰:

fig, ax = plt.subplots()
ax.pcolormesh(ex['x'], ex['y'], ex['z'])
for i, sweep_peak in enumerate(peaks):
    ax.scatter(ex['x'][sweep_peak[0]], ex['y'][i], 'rx')

我得到的错误是:

TypeError: ufunc 'sqrt' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

预先感谢您的帮助。

0 个答案:

没有答案