1

I have 2 variables that I would like to plot in separate subplots with errorbars. However, they both plot in the bottom subplot. How do I get them to plot in separate subplots?

from pandas import DataFrame, date_range, Timedelta
import numpy as np
from matplotlib import pyplot as plt

rng = date_range(start='2015-01-01', periods=5, freq='24H')
df = DataFrame({'y':np.random.normal(size=len(rng))}, index=rng)
y1 = df['y']
y2 = (y1*3)
sd1 = (y1*2)
sd2 = (y1*2)

fig,(ax1,ax2) = plt.subplots(2,1,sharex=True)

ax1 = y1.plot(yerr=sd1)
ax2 = y2.plot(yerr=sd2)

Example Photo

0

1 Answer 1

1

Use the ax parameter in pandas dataframe plot:

from pandas import DataFrame, date_range, Timedelta
import numpy as np
from matplotlib import pyplot as plt

rng = date_range(start='2015-01-01', periods=5, freq='24H')
df = DataFrame({'y':np.random.normal(size=len(rng))}, index=rng)
y1 = df['y']
y2 = (y1*3)
sd1 = (y1*2)
sd2 = (y1*2)

fig,(ax1,ax2) = plt.subplots(2,1,sharex=True)

_ = y1.plot(yerr=sd1, ax=ax1)
_ = y2.plot(yerr=sd2, ax=ax2)

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.