Dametime
Dametime

Reputation: 713

Pandas dataframe plot not sharing x axis label?

I have two subplots, but I would like both of them to share the same common Xlabel. Each subplot is coming from a separate dataframe. Problem is that, the xlabels are not being shared eventhough I used sharex=True. Each subplot is having it's own xlabel, from the dataframe column name.

Code:

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


df1.plot.line(ax=ax[0],x='X',y='Y',linestyle='--',
                 marker='s', color='tab:orange',legend=False, sharex=True)


df2.plot.line(ax=ax[1],x='X',y='Y',linestyle='--',
                  marker='s', color='tab:blue',legend=False, sharex=True)

plt.xlabel("Epoch")
plt.show()

Upvotes: 0

Views: 419

Answers (1)

Renaud
Renaud

Reputation: 2819

Are you expecting this kind of result: enter image description here

If yes, you need to correct:

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

by:

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

Upvotes: 1

Related Questions