Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib.pyplot: add horizontal line to sub-plot [duplicate]

This code (matplotlib.pyplot) gives me the plot in the link below:

plt.subplot(2, 1, 1)
plt.plot(px,py)

plt.subplot(2, 1, 2)
plt.plot(curve)

2 plots example --> I want to add a horizontal line in the second sub-plot at 100.000. How can I do that? The colors of both plots shall stay the same/synchronized.

like image 333
Mike Avatar asked Jul 09 '26 20:07

Mike


1 Answers

You can use matplotlib.axes.Axes.axhline of matplotlib which adds a horizontal line across the axis. If you need to set any further parameters, refer to the official documentation

import matplotlib.pyplot as plt    
plt.axhline(100000, color="gray")
like image 149
Giorgos Myrianthous Avatar answered Jul 11 '26 08:07

Giorgos Myrianthous



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!