Matplotlib Axes.axhline() Function in Python Last Updated : 23 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The matplotlib.axes.Axes.axhline() function allows you to add horizontal lines across your plot’s axes. This function is essential for creating reference lines, thresholds, or marking key values in your visualizations.Axes Class in MatplotlibThe Axes class is one of the core components in Matplotlib. It holds most of the figure elements such as Axis, Tick, Line2D, Text, and Polygon, and defines the coordinate system. Each Axes instance supports callbacks, enabling flexible plotting and interactions.Syntax: Axes.axhline(self, y=0, xmin=0, xmax=1)Parameters:y: The y-coordinate of the horizontal line (in data coordinates). Defaults to 0.xmin: The starting point of the horizontal line on the x-axis. Ranges from 0 (left) to 1 (right), with a default of 0.xmax: The ending point of the horizontal line on the x-axis. Similar to xmin, it ranges from 0 to 1, with a default of 1.Returns: A list of Line2D objects representing the horizontal lines.How to Use axhline() in Matplotlib?Example 1: Basic Usage Python import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [10, 20, 25, 30]) plt.axhline(y=20, color='r', linestyle='--', linewidth=2) plt.show() Output:line plot with a red horizontal line at y=20Example 2: Plot with Multiple Elements Python # Implementation of matplotlib function import matplotlib.pyplot as plt import matplotlib.tri as mtri import numpy as np fig, ax = plt.subplots() x = np.arange(0, 8 * np.pi, 0.01) y = np.sin(x) ax.plot(x, y, color ='black') threshold = 0.35 ax.axhline(threshold, color ='green',lw = 3, alpha = 0.7) ax.fill_between(x, 0, 1, where = y > threshold, color ='green', alpha = 0.8, transform = ax.get_xaxis_transform()) ax.set_title('matplotlib.axes.Axes.axhline() Example') plt.show() Output:A sine wave plot with a green threshold line at y=0.35.axhline() function in Matplotlib adds horizontal lines to plots. By adjusting its parameters, you can easily highlight key values, add reference lines, or customize your plot’s visual style. Comment More infoAdvertise with us Next Article Matplotlib.axis.Axis.draw() function in Python S SHUBHAMSINGH10 Follow Improve Article Tags : Python AI-ML-DS Python-matplotlib Practice Tags : python Similar Reads Matplotlib.axis.Axis.set() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack. Matplotlib.axis.Axis.set() Function The Axis.set() function in axis module of m 2 min read Matplotlib.axis.Axis.draw() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack. Matplotlib.axis.Axis.draw() Function The Axis.draw() function in axis module of 1 min read Matplotlib.axes.Axes.get_fc() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axis.Axis.update() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack. Matplotlib.axis.Axis.update() Function The Axis.update() function in axis modul 2 min read Matplotlib.axes.Axes.hlines() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axis.Axis.set_figure() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack. Matplotlib.axis.Axis.set_figure() Function The Axis.set_figure() function in ax 2 min read Like