Home > Mobile >  Pandas dataframe plot not sharing x axis label?
Pandas dataframe plot not sharing x axis label?

Time:10-23

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()

CodePudding user response:

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)
  • Related