Question: Enhance an existing plot by incorporating a horizontal line.
Solution:
To include a horizontal line on your plot, utilize axhline, which represents a horizontal line on the x-axis. This versatile function enables you to customize the line's position, color, and style.
For instance, to plot a horizontal line at y = 0.5, your code would look like this:
import matplotlib.pyplot as plt # Plot the horizontal line plt.axhline(y=0.5, color='r', linestyle='-') # Display the plot plt.show()
Here's an illustration of the resulting figure:
[Image of a sample figure with a horizontal line at y = 0.5]
By leveraging the capabilities of axhline, you can effortlessly enhance your plots with horizontal lines, adding clarity and depth to your visualizations.
The above is the detailed content of How to Add a Horizontal Line to an Existing Plot?. For more information, please follow other related articles on the PHP Chinese website!