Adding Horizontal Lines to Existing Plots
To include a horizontal line on a previously generated plot, the axhline function can be utilized, specifically designed to create horizontal axis lines.
Example Usage:
To illustrate its functionality, consider plotting a horizontal line at y = 0.5:
import matplotlib.pyplot as plt # Create plot # ... # Add horizontal line plt.axhline(y=0.5, color='r', linestyle='-') # Display plot plt.show()
Output:
The resulting plot will include a horizontal red line located at y = 0.5.
Additional Notes:
The above is the detailed content of How can I add a horizontal line to an existing plot in Matplotlib?. For more information, please follow other related articles on the PHP Chinese website!