How to add a horizontal line in Matplotlib

You can add a horizontal line in Matplotlib with the following code. If you want to learn Python then I will highly recommend you to read This Book.

How to add a horizontal line in Matplotlib
How to add a horizontal line in Matplotlib

Draw a horizontal line starting from 6 and ending at 14.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.hlines(y=3, xmin=6, xmax=14, linewidth=3, color='b')

plt.show()

Different Horizontal Lines

import matplotlib.pyplot as plt

plt.title("Horizontal Lines")

plt.axhline(y=0.2, color='green', linestyle='-')

plt.axhline(y=0.6, xmin=0.4, xmax=0.8, color='blue', linewidth=2)

plt.axhline(y=2, xmin=0.2, xmax=0.9,color='red', linestyle='-.', linewidth = 3)

plt.show()

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Top 10 Computer Vision Books with Python

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.