Home > Enterprise >  Adding a vertical line to Pandas subplot
Adding a vertical line to Pandas subplot

Time:04-11

I am trying to add a vertical line to a Pandas.dataframe.plot(subplot), but am struggling big time. Current Code:

df_final = df_final / df_final.max(axis=0)
df_final.loc[30102040].plot(subplots=True, layout=(17, 1), figsize=(25, 25), sharex=True, sharey=True)
plt.legend(loc='center left')
plt.axvline(sepsis_onset, color='red', linestyle='dashed')

plt.show()

what it currently looks like: Current Output

Neither the legend, nor the axvline is currently displayed correctly. What am I missing?

CodePudding user response:

I think that enter image description here

Of course you could also plot to only specific subplots:

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(1000, 4), columns=list("ABCD"))
df = df.cumsum()

axes = df.plot(subplots=True, figsize=(6, 6));

axes[1].axvline(20, color='red', linestyle='dashed')
plt.savefig("test_2.png", dpi=300)

result:

enter image description here

  • Related