My data points go like x = 1 to 10 and y = 0 to 1 and an array of 1000 points each.
>> 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]])
I have calculated the half-width from scipy.signal
for the y value and it looks like the below
>> (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]))
When I tried to plot the half-width maximum, I end up with a plot like the one below
what I want is a plot with the half-width maximum highlighted in this graph:
My Python code is
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()
I want to incorporate my half-width matching my x and y arrays not by line width with respect to data points.
CodePudding user response:
Solved it after understanding the array output from half_width: array[1] is the peak y_half_value, array[2] is X_min in line, array[3] is X_max...I also divided x_min and x_max by 100 to match my x-axis scale...
(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]))
So the python script for plotting is
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()
The output is: