1

I'm trying to plot two different dataframes on the same plot. But it only shows the second one. I have two dataframes: reconstructed and expected with the same shape. I need to plot them based on indexes (idx). So first I need to partition them based on each index; that is done by ts_rec = reconstructed.loc[idx] and ts_exp = expected.loc[idx]. Then I should plot these two new dataframes. Each of them has 28 columns, so I have 28 subplots with layout=(7, 4). The problem is that it only shows the second (red) timeseries, but I need to have both of them to be able to compare their values. How can I fix this?

ts_rec = reconstructed.loc[idx]
ts_exp = expected.loc[idx]
x = np.arange(ts_rec.shape[0])
ts_rec.plot(
    x=x, subplots=True, layout=(7, 4), lw=2, legend=False, 
    figsize=(12, 10), sharey=True, color='green')
ts_exp.plot(
    x=x, subplots=True, layout=(7, 4), lw=2, legend=False, 
    figsize=(12, 10), sharey=True, color='red')
pyplot.title("Timeseries id = %d" % idx)
pyplot.xlim(xmin=0)
pyplot.show()
pyplot.savefig(config['dir'] + 'ts_' + str(idx) + '.pdf')
pyplot.clf()

1 Answer 1

1

You just need to store the ax handle from the first plot and pass it as ax argument to the second plot:

plt_ax = ts_rec.plot(
    x=x, subplots=True, layout=(7, 4), lw=2, legend=False, 
    figsize=(12, 10), sharey=True, color='green')
ts_exp.plot(
    ax=plt_ax, x=x, subplots=True, layout=(7, 4), lw=2, legend=False, 
    figsize=(12, 10), sharey=True, color='red')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.