add a line to matplotlib subplots add a line to matplotlib subplots pandas pandas

add a line to matplotlib subplots


with the help of @Nick Becker I answered my own "syntax" question.

import pandas as pdimport matplotlib.pyplot as pltimport numpy as np%matplotlib inlines1= pd.Series(np.random.rand(10))s2= pd.Series(np.random.randn(10))fig, axes = plt.subplots(nrows=2,ncols=1)f1= s1.plot(ax=axes[0],label='s1')l1=axes[0].axhline(0.5,color='black',ls='--')l1.set_label('l1')axes[0].legend(loc='best')f2= s1.plot(ax=axes[1],label='s2')l2=axes[1].axhline(0.5,color='black',ls='--')l2.set_label('l2')axes[1].legend(loc='best')

subplots with horizontal lines