About 1,590,000 results
Open links in new tab
  1. python - Plot a horizontal line on a given plot - Stack Overflow

    Jun 16, 2022 · Use axhline (a horizontal axis line). For example, this plots a horizontal line at y = 0.5: If you want to draw a horizontal line in the axes, you might also try ax.hlines() method. You need to specify y position and xmin and xmax in the data coordinate (i.e, your actual data range in the x-axis). A sample code snippet is:

  2. matplotlib.axes.Axes.axhline — Matplotlib 3.10.1 documentation

    Add horizontal lines in data coordinates. axhspan. Add a horizontal span (rectangle) across the axis. axline. Add a line with an arbitrary slope.

  3. Plot a Horizontal line in Matplotlib - GeeksforGeeks

    Apr 2, 2025 · axhline() function is useful when you need to draw a horizontal line that spans the entire width of the plot, regardless of the x-axis limits. It is commonly used to mark thresholds, reference levels, or important divisions in data visualization.

  4. vertical & horizontal lines in matplotlib - Stack Overflow

    Jun 5, 2013 · The pyplot functions you are calling, axhline() and axvline() draw lines that span a portion of the axis range, regardless of coordinates. The parameters xmin or ymin use value 0.0 as the minimum of the axis and 1.0 as the maximum of the axis.

  5. python - Horizontal box plots in matplotlib/Pandas - Stack Overflow

    matplotlib offers the function bar and barh to do vertical and horizontal bar plots. matplotlib also offers the function boxplot to do vertical box plots. And Pandas offers its own function for vertical box plots. But is there any way in matplotlib or Pandas to get a horizontal box plot?

  6. 3 Convenient Methods to Plot a Horizontal or Vertical Line

    Jun 24, 2023 · In this tutorial, we will explore three different methods to achieve this using Matplotlib: the ‘axhline’ and ‘axvline’ functions, the ‘plot’ function, and the ‘hlines’ and ‘vlines’ functions.

  7. Plotting a Horizontal Line Using Matplotlib: A Guide for Data ...

    Aug 7, 2023 · To plot a horizontal line, we’ll use the axhline() function. This function draws a horizontal line across the entire x-axis. Here’s a simple example: In this example, y=0.5 sets the position of the line across the y-axis, color='r' sets the color of the line to red, and linestyle='-' sets the line style to a solid line.

  8. Enhancing Data Visualizations with Horizontal Lines in Python

    Feb 18, 2025 · Pandas plots are essentially built on Matplotlib, so we can directly use plt.axhline() to add a horizontal line to a Pandas plot. You can further customize the horizontal line by: Adding a label label='Threshold' and using plt.legend()

  9. How to plot a horizontal line in matplotlib - Altcademy Blog

    Jan 21, 2024 · To create a horizontal line that spans from x=1 to x=3, you can use the hlines function. Here's how: In this example, xmin and xmax define the start and end points of the line on the x-axis, and y defines the constant y-value. The line is green ('g') and has a thickness of 2.

  10. How To Plot Vertical And Horizontal Lines in Matplotlib

    Jan 9, 2023 · In this tutorial, we will demonstrate how to use matplotlib functions to plot vertical and horizontal lines in an existing plot. We will also discuss some of the options and considerations you should keep in mind when adding lines to your plots.

Refresh