I;m working in python and found a couple solutions to do this. But it requires creating each individual subplot. But since there's a parameter where you could do subplot=True
, I'm wondering is there a way to to do it in one line of code...much how you could say sharey=True
, can you make it "share" a horizontal constant?
I've been playing around with it. At first, it was only showing up on the last graph, but now it's not showing at all.
import matplotlib.pyplot as plt
line_up_points.plot(subplots=True, layout=(3, 3),sharey=True, figsize=(18, 12))
plt.legend(loc='best')
plt.axhline(y=125.08, color='r')
Here's what it's showing:
But I would like to have a horizontal line on each of those subplots at y=125.08
Any idea without individually creating 7 different graphs?
If I'm not mistaken then you should get back a matrix of axis objects.
This should do the trick:
axes = line_up_points.plot(subplots=True, layout=(3, 3),sharey=True, figsize=(18, 12))
for c in axes:
for ax in c:
ax.axhline(y=125.08, color='r')
Here's a full example:
%matplotlib inline # For Jupyter Notebooks
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.rand(10, 7))
axes = df.plot(subplots=True, layout=(3, 3), figsize=(16,9))
for c in axes:
for ax in c:
ax.axhline(y=0.5, color='r')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With