iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use ax.axvline(x=...) to add a vertical reference line to a Matplotlib plot. It spans the Axes height by default. If you need a line segment whose top and bottom are specified as y-axis data values, use ax.vlines() instead.
Add a full-height reference line with ax.axvline()
Call ax.axvline() on the Axes that contains your plot. The x argument is the line’s position in data coordinates.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [2, 1, 3])
ax.axvline(x=1, color="red", linestyle="--", linewidth=1.5)
plt.show()
This draws a dashed red line at x = 1, spanning the Axes height. The Matplotlib API describes axvline as adding “a vertical line spanning the whole or fraction of the Axes.” Matplotlib’s axvline API reference documents the arguments and return value.
Recommended Free Tools
Control how much of the Axes the line spans
For a line covering only part of the plot’s height, pass ymin and ymax as fractions of the Axes height. These values use Axes coordinates, not y-axis data values: 0 is the bottom edge and 1 is the top edge.
#1 Best Overall
- Ideal for graphing, charts and engineering projects.
- 1-subject notebook. 100 double-sided, graph ruled sheets. 4 squares per inch.
- Sheets measure 8-1/2 in. x 11 in. when torn out. Overall notebook size is 11 in. x 9-3/4 in. Tough pockets help prevent tears and hold 8-1/2 in. x 11 in. loose sheets.
- High-grade paper fights ink bleed. Perforated pages for easy tear out. Front cover is water-resistant to help protect your notes all year.
- Spiral Lock wire helps prevent snags on clothes and backpacks. Made with SFI approved paper. Recyclable - remove reinforcement tape on pocket and recycle the rest.
ax.axvline(x=1, ymin=0.25, ymax=0.75)
This draws the line through the middle half of the Axes, regardless of the plotted y-data limits. The x position remains in data coordinates.
Use ax.vlines() for endpoints in y data coordinates
When the line should run between actual y values, use ax.vlines(x, ymin, ymax). Unlike axvline, its ymin and ymax arguments are y-axis data values. Matplotlib’s vlines API reference also documents scalar or array-like positions and endpoints.
Rank #2
- 1 subject notebook comes with 100 graph ruled, double-sided sheets with 5 squares per inch
- Sheets measure 7-1/2" x 10-1/2" when torn out with an overall size of 8" x 10-1/2". Perforation easily tears out with clean edges.
- Graph ruling is ideal for plotting graphs, drawing curves and more. Notebook is 3-hole punched to store in your favorite binder.
- Covers are coated for durability and have writable label on front cover. Available in Black.
- Assembled in U.S.A. with U.S. and foreign parts
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [2, 5, 3])
ax.vlines(x=1, ymin=2, ymax=5, color="black", linestyle=":")
plt.show()
This example draws a dotted segment at x = 1 from y = 2 to y = 5. You can supply multiple x positions and corresponding endpoints when you need several data-bounded vertical lines.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Style or move the line
ax.axvline() accepts standard line properties, including color, linestyle, and linewidth, as shown in the first example. It returns a Line2D object, which you can keep and update. To move an existing vertical line to x = 3, set both x endpoints to the same value:
Rank #3
- 1 subject notebook comes with 100 graph ruled, double-sided sheets with 5 squares per inch
- Sheets measure 7-1/2" x 10-1/2" when torn out with an overall size of 8" x 10-1/2". Perforation easily tears out with clean edges.
- Graph ruling is ideal for plotting graphs, drawing curves and more. Notebook is 3-hole punched to store in your favorite binder.
- Covers are coated for durability and have writable label on front cover. Available in Green.
- Assembled in U.S.A. with U.S. and foreign parts
line = ax.axvline(x=1)
line.set_xdata([3, 3])
For a pyplot-style call, plt.axvline(...) is also available; Matplotlib documents it as a wrapper for Axes.axvline. Using ax.axvline(...) makes the target Axes explicit. For a runnable reference-line example, see the Matplotlib Infinite lines gallery.
Quick Recap
Best Value
- SUNEE 1 SUBJECT NOTEBOOK: Single subject spiral notebook with 100 sheets/200 Pages of graph paper, you'll have plenty of space for notes and assignments. Get the best value with our graph paper notebook and stay organized.
- GRAPH NOTEBOOK: Each 8" x 10-1/2" grid notebook features 100 double-sided sheets with red margin lines and is 3-hole punched, easily transfer to your favorite binder. It's the ideal grid paper notebook for all your academic and professional needs.
- 3-HOLE PUNCHED DESIGN: Designed with 3-hole punched graph paper, this math notebook integrates seamlessly into standard binders; Perfect for who need to keep their notes organized in one place, notebook grid clutter in your study or work area.
- CLEAN TEAR-OUT: Micro-perforated pages ensure a neat tear-out, leaving you with 10 1/2" x 7 1/2" sheets. Accommodates double-sided writing. Sunee graph paper spiral notebook offers premium quality at an affordable price. A graphing notebook is perfect for students, teachers, and professionals.
- DURABLE & FUNCTIONAL DESIGN: Water-resistant plastic cover provides extra protection, making this spiral graph paper notebook ideal for on-the-go, frequent transfers in and out of backpacks, briefcases, and vehicles. The double-sided pockets are great for storing loose papers and handouts, making this one subject graph spiral notebook a practical choice for students and professionals.
Rank #4
- LASTS ALL YEAR. GUARANTEED!* Water resistant covers protect your notes all year.
- High-quality paper resists ink bleed** so notes stay clear and legible. Notebook has 100 graph ruled sheets, 4 squares per inch.
- Includes storage pocket to hold loose sheets from the notebook. Patented, reinforced storage pocket helps prevent tears.***
- Spiral Lock wire prevents coil snags so it won’t get caught on your clothes or backpack. The Neat Sheet perforated pages easily tear out with clean edges.
- Perforated sheets measure 11" x 8-1/2" when torn out. Overall size of 11" x 9 1/8". Available in Teal.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

