How to Draw Vertical Lines on a Time Series Plot in Python?

Mary-Kate Olsen
Release: 2024-11-23 19:00:15
Original
478 people have browsed it

How to Draw Vertical Lines on a Time Series Plot in Python?

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)
Copy after login

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)
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template