{"id":5783,"date":"2020-12-07T06:59:13","date_gmt":"2020-12-07T01:29:13","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=5783"},"modified":"2026-07-13T12:29:06","modified_gmt":"2026-07-13T06:59:06","slug":"matplotlib-vertical-lines","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/","title":{"rendered":"Matplotlib Vertical Lines: axvline(), vlines(), and plot()"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> Use axvline() for a vertical marker that spans the axes, vlines() for vertical segments defined in data coordinates, and plot() when a line should behave like ordinary x-y data. Choose the function from the coordinate system you need.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-line-coordinates.png\" alt=\"Matplotlib vertical line diagram comparing axvline vlines and plot with axes and data coordinate systems\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>Use axvline() for an axes-spanning marker and vlines() when both ends belong to data coordinates.<\/figcaption><\/figure>\n<p>Vertical lines are useful reference markers in Matplotlib charts. You can mark a threshold, event time, cutoff, peak location, or comparison point without changing the plotted data.<\/p>\n<p>The three common ways to draw vertical lines are <code>ax.axvline()<\/code>, <code>ax.vlines()<\/code>, and <code>ax.plot()<\/code>. The best choice depends on whether the line should span the whole Axes, use exact y-data limits, or behave like a regular plotted line.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Quick_Choice_axvline_vs_vlines_vs_plot\" >Quick Choice: axvline vs vlines vs plot<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Draw_One_Vertical_Line_With_axvline\" >Draw One Vertical Line With axvline()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Draw_a_Partial-Height_axvline\" >Draw a Partial-Height axvline()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Use_vlines_for_Data-Coordinate_y_Limits\" >Use vlines() for Data-Coordinate y Limits<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Draw_a_Vertical_Line_With_plot\" >Draw a Vertical Line With plot()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Add_Labels_to_Vertical_Lines\" >Add Labels to Vertical Lines<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Common_Styling_Options\" >Common Styling Options<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Common_Mistakes\" >Common Mistakes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Related_Matplotlib_Guides\" >Related Matplotlib Guides<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Official_References\" >Official References<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Understand_The_Coordinate_Systems\" >Understand The Coordinate Systems<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Use_vlines_For_Data_Segments\" >Use vlines For Data Segments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Choose_Limits_And_Labels\" >Choose Limits And Labels<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#How_do_I_draw_a_vertical_line_in_Matplotlib\" >How do I draw a vertical line in Matplotlib?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#What_is_the_difference_between_axvline_and_vlines\" >What is the difference between axvline() and vlines()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#How_do_I_draw_multiple_vertical_lines\" >How do I draw multiple vertical lines?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#How_do_I_label_a_vertical_line\" >How do I label a vertical line?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Quick_Choice_axvline_vs_vlines_vs_plot\"><\/span>Quick Choice: axvline vs vlines vs plot<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"pythonpool-table-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Best use<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>ax.axvline()<\/code><\/td>\n<td>One vertical reference line that spans all or part of the Axes height.<\/td>\n<\/tr>\n<tr>\n<td><code>ax.vlines()<\/code><\/td>\n<td>One or many vertical lines with y start and y end in data coordinates.<\/td>\n<\/tr>\n<tr>\n<td><code>ax.plot([x, x], [y1, y2])<\/code><\/td>\n<td>A vertical line that should behave like any other plotted line.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Draw_One_Vertical_Line_With_axvline\"><\/span>Draw One Vertical Line With axvline()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>axvline()<\/code> is the simplest option for a full-height reference line. The <code>x<\/code> value is in data coordinates, while <code>ymin<\/code> and <code>ymax<\/code> are in axes-fraction coordinates from <code>0<\/code> to <code>1<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre class=\"wp-block-code\"><code>import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.linspace(0, 10, 100)\ny = np.sin(x)\n\nfig, ax = plt.subplots()\nax.plot(x, y)\n\nax.axvline(x=3, color=\"crimson\", linestyle=\"--\", linewidth=2)\n\nplt.show()<\/code><\/pre>\n<\/div>\n<p>Because <code>ymin=0<\/code> and <code>ymax=1<\/code> by default, the line runs from the bottom to the top of the Axes.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/vertical-goal-b154.png\" alt=\"Python Pool infographic showing a plot, x position, full-height marker, and an axvline reference\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Vertical marker: A plot, x position, full-height marker, and an axvline reference.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Draw_a_Partial-Height_axvline\"><\/span>Draw a Partial-Height axvline()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>ymin<\/code> and <code>ymax<\/code> when the line should cover only part of the plot height. Remember that these values are not y-data values.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre class=\"wp-block-code\"><code>ax.axvline(\n    x=5,\n    ymin=0.2,\n    ymax=0.8,\n    color=\"black\",\n    linestyle=\":\",\n    linewidth=2,\n)<\/code><\/pre>\n<\/div>\n<p>This draws a vertical line at <code>x=5<\/code> from 20% to 80% of the Axes height. If you need y positions such as <code>ymin=-0.5<\/code> and <code>ymax=0.5<\/code> in data units, use <code>vlines()<\/code> instead.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_vlines_for_Data-Coordinate_y_Limits\"><\/span>Use vlines() for Data-Coordinate y Limits<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>vlines()<\/code> accepts one x value or many x values. Its <code>ymin<\/code> and <code>ymax<\/code> values are data coordinates, which makes it better for vertical intervals.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre class=\"wp-block-code\"><code>fig, ax = plt.subplots()\nax.plot(x, y)\n\nax.vlines(\n    x=[2, 4, 6],\n    ymin=-0.5,\n    ymax=0.5,\n    colors=\"seagreen\",\n    linestyles=\"solid\",\n    linewidth=2,\n)\n\nplt.show()<\/code><\/pre>\n<\/div>\n<p>This draws three vertical line segments. Each segment starts at <code>y=-0.5<\/code> and ends at <code>y=0.5<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Draw_a_Vertical_Line_With_plot\"><\/span>Draw a Vertical Line With plot()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can also draw a vertical line by plotting two points with the same x value.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre class=\"wp-block-code\"><code>ax.plot([7, 7], [-1, 1], color=\"orange\", linewidth=3)<\/code><\/pre>\n<\/div>\n<p>This is useful when you want the line to be part of a normal line plot workflow. For most reference markers, <code>axvline()<\/code> or <code>vlines()<\/code> communicates the intent more clearly.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/vertical-methods-b154.png\" alt=\"Python Pool infographic comparing axvline, vlines, and plot for coordinate and span behavior\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Line methods: Axvline, vlines, and plot for coordinate and span behavior.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Add_Labels_to_Vertical_Lines\"><\/span>Add Labels to Vertical Lines<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A vertical line is often more useful with a label. Use <code>annotate()<\/code> when the label should point to the marker.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre class=\"wp-block-code\"><code>ax.axvline(x=3, color=\"crimson\", linestyle=\"--\")\n\nax.annotate(\n    \"cutoff\",\n    xy=(3, 0.8),\n    xycoords=(\"data\", \"axes fraction\"),\n    xytext=(8, 0),\n    textcoords=\"offset points\",\n    color=\"crimson\",\n)<\/code><\/pre>\n<\/div>\n<p>For more callout patterns, see the <a href=\"https:\/\/www.pythonpool.com\/matplotlib-annotate\/\">Matplotlib annotate guide<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Common_Styling_Options\"><\/span>Common Styling Options<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Vertical-line methods accept regular Matplotlib line styling options such as <code>color<\/code>, <code>linestyle<\/code>, <code>linewidth<\/code>, <code>alpha<\/code>, and <code>label<\/code>.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre class=\"wp-block-code\"><code>ax.axvline(\n    x=3,\n    color=\"crimson\",\n    linestyle=\"--\",\n    linewidth=2,\n    alpha=0.8,\n    label=\"event\",\n)\nax.legend()<\/code><\/pre>\n<\/div>\n<p>If the vertical line makes the chart look too busy, reduce <code>alpha<\/code>, use a dashed line, or choose a muted color.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/vertical-style-b154.png\" alt=\"Python Pool infographic mapping a vertical line through color, linestyle, linewidth, alpha, and label\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Line styling: A vertical line through color, linestyle, linewidth, alpha, and label.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Common_Mistakes\"><\/span>Common Mistakes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Using <code>axvline()<\/code> with y-data limits.<\/strong> Its <code>ymin<\/code> and <code>ymax<\/code> are axes-fraction values, not y-axis values.<\/li>\n<li><strong>Forgetting axis limits.<\/strong> If the marker is outside the x-axis range, it will not be visible. Check current limits with <a href=\"https:\/\/www.pythonpool.com\/matplotlib-ylim\/\">Matplotlib ylim<\/a> and matching x-axis methods.<\/li>\n<li><strong>Adding too many reference lines.<\/strong> Use <code>vlines()<\/code> for repeated markers and choose light styling.<\/li>\n<li><strong>Calling pyplot functions in multi-axes figures.<\/strong> Prefer <code>ax.axvline()<\/code> and <code>ax.vlines()<\/code> on the intended Axes. The <a href=\"https:\/\/www.pythonpool.com\/matplotlib-gca\/\">Matplotlib gca guide<\/a> explains current Axes behavior.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Related_Matplotlib_Guides\"><\/span>Related Matplotlib Guides<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For more plot styling, read <a href=\"https:\/\/www.pythonpool.com\/matplotlib-background-color\/\">how to change Matplotlib background color<\/a>, <a href=\"https:\/\/www.pythonpool.com\/clear-plot-matplotlib\/\">how to clear a Matplotlib plot<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/\">Matplotlib pcolormesh<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Official_References\"><\/span>Official References<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><a href=\"https:\/\/matplotlib.org\/stable\/api\/_as_gen\/matplotlib.axes.Axes.axvline.html\" rel=\"nofollow noopener\" target=\"_blank\">Matplotlib Axes.axvline documentation<\/a><\/li>\n<li><a href=\"https:\/\/matplotlib.org\/stable\/api\/_as_gen\/matplotlib.axes.Axes.vlines.html\" rel=\"nofollow noopener\" target=\"_blank\">Matplotlib Axes.vlines documentation<\/a><\/li>\n<li><a href=\"https:\/\/matplotlib.org\/stable\/api\/_as_gen\/matplotlib.pyplot.axvline.html\" rel=\"nofollow noopener\" target=\"_blank\">Matplotlib pyplot.axvline documentation<\/a><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>ax.axvline()<\/code> for simple full-height reference markers, <code>ax.vlines()<\/code> for one or many vertical segments with y-data limits, and <code>ax.plot()<\/code> when the marker should act like a regular line. The main thing to remember is the coordinate difference between <code>axvline()<\/code> and <code>vlines()<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Understand_The_Coordinate_Systems\"><\/span>Understand The Coordinate Systems<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>axvline(x)<\/code> takes <code>x<\/code> in data coordinates, while its default y extent uses axes coordinates from bottom to top. That makes it useful for a reference marker that should span the plot even when the y limits change.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nfig, ax = plt.subplots()\nax.plot([0, 1, 2], [2, 1, 3])\nax.axvline(1, color=\"crimson\", linestyle=\"--\", label=\"threshold\")\nax.legend()\nplt.show()\n<\/code><\/pre>\n<\/div>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/vertical-check-b154.png\" alt=\"Python Pool infographic testing axis limits, transforms, legends, multiple markers, and export\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Marker checks: Axis limits, transforms, legends, multiple markers, and export.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Use_vlines_For_Data_Segments\"><\/span>Use vlines For Data Segments<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>ax.vlines()<\/code> when each vertical line has data-coordinate starts and ends. This is a better fit for intervals, error bars, or many segments with different heights.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">ax.vlines([0.5, 1.5], ymin=[0, 1], ymax=[2, 3], color=\"black\")\n<\/code><\/pre>\n<\/div>\n<p>Labels, legends, clipping, z-order, and line styles are separate presentation decisions. Give a marker a useful label only when the legend helps explain the plot, and choose a color that remains readable when the figure is printed or viewed without color.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Choose_Limits_And_Labels\"><\/span>Choose Limits And Labels<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>ax.set_xlim()<\/code> when a marker should be visible inside a known range, and use a concise label when the line represents a threshold or event. A vertical line should support the data story rather than obscure a dense series.<\/p>\n<p>For repeated markers, keep the positions in a list and use one call to <code>vlines()<\/code> where possible. This keeps styling consistent and makes later changes to the marker set easier to review.<br \/>\nThat approach also makes it easier to test the marker positions separately from the plot styling. Keep the data-coordinate limits explicit when the segments must align with other plotted measurements.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_draw_a_vertical_line_in_Matplotlib\"><\/span>How do I draw a vertical line in Matplotlib?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Call axvline(x=value) to draw a vertical marker at a data-coordinate x position across the axes by default.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_axvline_and_vlines\"><\/span>What is the difference between axvline() and vlines()?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>axvline() combines a data-coordinate x value with an axes-spanning y extent, while vlines() uses data coordinates for x, ymin, and ymax.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_draw_multiple_vertical_lines\"><\/span>How do I draw multiple vertical lines?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Store the marker positions in a sequence and use repeated axvline() calls or one vlines() call when the data-space segments share styling.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_label_a_vertical_line\"><\/span>How do I label a vertical line?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Pass a label to the line artist and call ax.legend(), or annotate the marker directly when the label needs a specific position.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"How do I draw a vertical line in Matplotlib?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Call axvline(x=value) to draw a vertical marker at a data-coordinate x position across the axes by default.\"}},{\"@type\":\"Question\",\"name\":\"What is the difference between axvline() and vlines()?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"axvline() combines a data-coordinate x value with an axes-spanning y extent, while vlines() uses data coordinates for x, ymin, and ymax.\"}},{\"@type\":\"Question\",\"name\":\"How do I draw multiple vertical lines?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Store the marker positions in a sequence and use repeated axvline() calls or one vlines() call when the data-space segments share styling.\"}},{\"@type\":\"Question\",\"name\":\"How do I label a vertical line?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Pass a label to the line artist and call ax.legend(), or annotate the marker directly when the label needs a specific position.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Draw Matplotlib vertical markers with axvline(), data-space segments with vlines(), and ordinary line data with plot().<\/p>\n","protected":false},"author":1,"featured_media":32127,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2071],"tags":[2615,2613,2614,2612,2616],"class_list":["post-5783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-matplotlib","tag-draw-vertical-line-matplotlib","tag-matplotlib-plot-vertical-line","tag-matplotlib-vertical-line","tag-plot-vertical-line-matplotlib","tag-vertical-line-matplotlib","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Matplotlib Vertical Lines: axvline(), vlines(), and plot()<\/title>\n<meta name=\"description\" content=\"Draw Matplotlib vertical lines with axvline(), vlines(), and plot(), control coordinates, limits, styling, labels, and multiple markers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Matplotlib Vertical Lines: axvline(), vlines(), and plot()\" \/>\n<meta property=\"og:description\" content=\"Draw Matplotlib vertical markers with axvline(), data-space segments with vlines(), and ordinary line data with plot().\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-07T01:29:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T06:59:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-line-coordinates.png\" \/>\n<meta name=\"author\" content=\"Python Pool\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-line-coordinates.png\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Python Pool\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/\"},\"author\":{\"name\":\"Python Pool\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/f87448ee54c0ffd2889fbf2408c18998\"},\"headline\":\"Matplotlib Vertical Lines: axvline(), vlines(), and plot()\",\"datePublished\":\"2020-12-07T01:29:13+00:00\",\"dateModified\":\"2026-07-13T06:59:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/\"},\"wordCount\":946,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-vertical-lines-axvline-vlines.png\",\"keywords\":[\"draw vertical line matplotlib\",\"matplotlib plot vertical line\",\"matplotlib vertical line\",\"plot vertical line matplotlib\",\"vertical line matplotlib\"],\"articleSection\":[\"Matplotlib\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/\",\"name\":\"Matplotlib Vertical Lines: axvline(), vlines(), and plot()\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-vertical-lines-axvline-vlines.png\",\"datePublished\":\"2020-12-07T01:29:13+00:00\",\"dateModified\":\"2026-07-13T06:59:06+00:00\",\"description\":\"Draw Matplotlib vertical lines with axvline(), vlines(), and plot(), control coordinates, limits, styling, labels, and multiple markers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-vertical-lines-axvline-vlines.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-vertical-lines-axvline-vlines.png\",\"width\":1350,\"height\":650,\"caption\":\"Matplotlib vertical lines example with axvline vlines and linestyle\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-vertical-lines\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Matplotlib Vertical Lines: axvline(), vlines(), and plot()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pythonpool.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/pythonpool\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/f87448ee54c0ffd2889fbf2408c18998\",\"name\":\"Python Pool\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"caption\":\"Python Pool\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Matplotlib Vertical Lines: axvline(), vlines(), and plot()","description":"Draw Matplotlib vertical lines with axvline(), vlines(), and plot(), control coordinates, limits, styling, labels, and multiple markers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/","og_locale":"en_US","og_type":"article","og_title":"Matplotlib Vertical Lines: axvline(), vlines(), and plot()","og_description":"Draw Matplotlib vertical markers with axvline(), data-space segments with vlines(), and ordinary line data with plot().","og_url":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/","og_site_name":"Python Pool","article_published_time":"2020-12-07T01:29:13+00:00","article_modified_time":"2026-07-13T06:59:06+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-line-coordinates.png","type":"","width":"","height":""}],"author":"Python Pool","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-line-coordinates.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Python Pool","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/"},"author":{"name":"Python Pool","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998"},"headline":"Matplotlib Vertical Lines: axvline(), vlines(), and plot()","datePublished":"2020-12-07T01:29:13+00:00","dateModified":"2026-07-13T06:59:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/"},"wordCount":946,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-lines-axvline-vlines.png","keywords":["draw vertical line matplotlib","matplotlib plot vertical line","matplotlib vertical line","plot vertical line matplotlib","vertical line matplotlib"],"articleSection":["Matplotlib"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/","url":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/","name":"Matplotlib Vertical Lines: axvline(), vlines(), and plot()","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-lines-axvline-vlines.png","datePublished":"2020-12-07T01:29:13+00:00","dateModified":"2026-07-13T06:59:06+00:00","description":"Draw Matplotlib vertical lines with axvline(), vlines(), and plot(), control coordinates, limits, styling, labels, and multiple markers.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-lines-axvline-vlines.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-vertical-lines-axvline-vlines.png","width":1350,"height":650,"caption":"Matplotlib vertical lines example with axvline vlines and linestyle"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/matplotlib-vertical-lines\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Matplotlib Vertical Lines: axvline(), vlines(), and plot()"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998","name":"Python Pool","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","caption":"Python Pool"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=5783"}],"version-history":[{"count":23,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5783\/revisions"}],"predecessor-version":[{"id":41464,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/5783\/revisions\/41464"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/32127"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=5783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=5783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=5783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}