Given a signal plot with a time index ranging from 0 to 2.6 seconds, vertical lines can be drawn to mark specific time indices. To achieve this, the plt.axvline function is commonly used.
To draw a vertical line at a specific time index, simply provide the x argument with the desired time value. For example:
import matplotlib.pyplot as plt # Draw a line at time index 0.22058956 plt.axvline(x=0.22058956)
To draw multiple lines, pass a list of time indices to the x argument:
xcoords = [0.22058956, 0.33088437, 2.20589566] for xc in xcoords: plt.axvline(x=xc)
Customization options are also available. For instance, the color, linestyle, and linewidth can be adjusted using specified keywords.
Additionally, ymin and ymax can be used to set the vertical extent of the line in axes coordinates. For example, to have the line cover the middle half of the plot:
plt.axvline(x=0.22058956, ymin=0.25, ymax=0.75)
Corresponding functions exist for horizontal lines (axhline) and rectangles (axvspan) to mark other spatial dimensions.
The above is the detailed content of How to Mark Time Indices on Signal Plots with Vertical Lines?. For more information, please follow other related articles on the PHP Chinese website!