matplotlib 中的线图
hline plot in matplotlib
我的数据点像 x = 1 到 10 和 y = 0 到 1 以及每个 1000 个点的数组。
>> array([[0.00000e+00, 1.00000e+00],
[1.00000e-02, 9.79893e-01],
[2.00000e-02, 9.21879e-01],
...,
[9.99000e+00, 2.15619e-01],
[1.00000e+01, 2.15619e-01],
[1.00100e+01, 2.15618e-01]])
我已经根据 scipy.signal
计算出 half-width 的 y 值,它看起来像下面的
>> (array([0.395881 , 0.324863 , 0.3012635, 0.283398 , 0.269297 , 0.2587625]),
array([ 14.74704647, 33.76801591, 52.65272424, 71.46096096,
90.27218935, 109.05898876]),
array([ 24.53566146, 43.76762879, 62.05528877, 79.78986366,
97.06749311, 113.20798898]))
当我尝试绘制 half-width 最大值时,我得到了如下图所示的图
我想要的是图中突出显示 half-width 最大值的图:
我的Python密码是
fig = plt.figure()
ax = fig.subplots()
ax.plot(x,y)
ax.scatter(peak_pos, height, color = 'r', s = 10, marker = 'D', label = 'maxima')
#ax.hlines(*results_half[1:], color="C2")
ax.legend()
ax.grid()
plt.show()
我想合并我的 half-width 匹配我的 x 和 y 数组,而不是根据数据点的线宽。
了解了half_width输出的数组后解决了:array[1]是峰值y_half_value,array[2]是X_min在直线上,array[3]是X_max...我还将 x_min 和 x_max 除以 100 以匹配我的 x-axis 比例...
(array([9.78861498, 9.99961288, 9.40256452, 8.3289027 , 6.79530376,
4.14900022]),
array([0.395881 , 0.324863 , 0.3012635, 0.283398 , 0.269297 , 0.2587625]),
array([ 14.74704647, 33.76801591, 52.65272424, 71.46096096,
90.27218935, 109.05898876]),
array([ 24.53566146, 43.76762879, 62.05528877, 79.78986366,
97.06749311, 113.20798898]))
所以python绘图脚本是
fig = plt.figure()
ax = fig.subplots()
ax.plot(x,y)
ax.scatter(peak_pos, height, color = 'r', s = 10, marker = 'D', label = 'maxima')
ax.hlines(results_half[1], newList[0], newList[1], color="C3")
#ax.scatter(min_pos, min_height*-1, color = 'gold', s = 10, marker = 'X', label = 'minima')
ax.legend()
#ax.grid()
plt.show()
输出为:
我的数据点像 x = 1 到 10 和 y = 0 到 1 以及每个 1000 个点的数组。
>> array([[0.00000e+00, 1.00000e+00],
[1.00000e-02, 9.79893e-01],
[2.00000e-02, 9.21879e-01],
...,
[9.99000e+00, 2.15619e-01],
[1.00000e+01, 2.15619e-01],
[1.00100e+01, 2.15618e-01]])
我已经根据 scipy.signal
计算出 half-width 的 y 值,它看起来像下面的
>> (array([0.395881 , 0.324863 , 0.3012635, 0.283398 , 0.269297 , 0.2587625]),
array([ 14.74704647, 33.76801591, 52.65272424, 71.46096096,
90.27218935, 109.05898876]),
array([ 24.53566146, 43.76762879, 62.05528877, 79.78986366,
97.06749311, 113.20798898]))
当我尝试绘制 half-width 最大值时,我得到了如下图所示的图
我想要的是图中突出显示 half-width 最大值的图:
我的Python密码是
fig = plt.figure()
ax = fig.subplots()
ax.plot(x,y)
ax.scatter(peak_pos, height, color = 'r', s = 10, marker = 'D', label = 'maxima')
#ax.hlines(*results_half[1:], color="C2")
ax.legend()
ax.grid()
plt.show()
我想合并我的 half-width 匹配我的 x 和 y 数组,而不是根据数据点的线宽。
了解了half_width输出的数组后解决了:array[1]是峰值y_half_value,array[2]是X_min在直线上,array[3]是X_max...我还将 x_min 和 x_max 除以 100 以匹配我的 x-axis 比例...
(array([9.78861498, 9.99961288, 9.40256452, 8.3289027 , 6.79530376,
4.14900022]),
array([0.395881 , 0.324863 , 0.3012635, 0.283398 , 0.269297 , 0.2587625]),
array([ 14.74704647, 33.76801591, 52.65272424, 71.46096096,
90.27218935, 109.05898876]),
array([ 24.53566146, 43.76762879, 62.05528877, 79.78986366,
97.06749311, 113.20798898]))
所以python绘图脚本是
fig = plt.figure()
ax = fig.subplots()
ax.plot(x,y)
ax.scatter(peak_pos, height, color = 'r', s = 10, marker = 'D', label = 'maxima')
ax.hlines(results_half[1], newList[0], newList[1], color="C3")
#ax.scatter(min_pos, min_height*-1, color = 'gold', s = 10, marker = 'X', label = 'minima')
ax.legend()
#ax.grid()
plt.show()
输出为: