Drawing Vertical Lines on a Plot
To overlay vertical lines on a time series plot, indicating specific time indices, there are a few approaches available.
Using plt.axvline
The simplest method is to use plt.axvline, which draws a vertical line at the specified x-coordinate. Simply provide the coordinate:
import matplotlib.pyplot as plt plt.axvline(x=0.22058956) plt.axvline(x=0.33088437) plt.axvline(x=2.20589566)
Using a Loop with plt.axvline
Alternatively, you can iterate through a list of coordinates to draw multiple vertical lines:
xcoords = [0.22058956, 0.33088437, 2.20589566] for xc in xcoords: plt.axvline(x=xc)
Both methods allow for customization of line properties such as color, style, and width using the corresponding keyword arguments.
The above is the detailed content of How to Draw Vertical Lines on a Time Series Plot in Python?. For more information, please follow other related articles on the PHP Chinese website!