I have been having issues regarding signal processing. I am fairly new with programming so I may be completely wrong. I wrote code for a textbox widget in matplotlib. I want to be able to plot evenly-spaced markers on a graph. The number of markers that someone wants to add will be entered in the textbox. Right now I have a numpy linspace
function, where it starts at 0 and stops at len(x_data)
with num
being equal to the number of markers I want to add. For some reason the markers plot on top of each other. So instead of plotting 10 markers on the graph it only plots 5 markers where the markers are plotted on top of each other. Am I doing something wrong?
def process_points(event):
ax2.cla()
number_of_points = int(text2_box1.text)
marker_indices = np.linspace(0, len(x_data)-1, number_of_points, dtype=int)
x_markers = x_data[marker_indices]
y_markers = y_data[marker_indices]
ax2.plot(x_data, y_data, color='blue')
ax2.set_xlabel('Frequency (Hz)')
ax2.set_ylabel('Amplitude')
ax2.set_title('Data between lines')
for x, y in zip(x_markers, y_markers):
ax2.plot(x, y, '.', color='crimson')
plt.show()
Example of what I mean:
Edit: Updated code:
def process_points(event):
ax2.cla()
number_of_points = int(text2_box1.text)
x_markers = np.linspace(0, x_data[-1],number_of_points)
ax2.semilogy(x_data, y_data, color='blue')
ax2.set_xlabel('Frequency (Hz)')
ax2.set_ylabel('Amplitude')
ax2.set_title('Data between lines')
y_markers = np.interp(x_markers, x_data, y_data)
ax2.scatter(x_markers, y_markers, color='crimson')
ax2.grid(True, which='both', axis='both')
plt.show()