0

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()
1
  • Please add some test data to make the code reproducible. Are the X values integers, floats, strings, dates, categorical, ...? Please also add an image of the obtained plot. Are you using the latest pandas and matplotlib versions? Commented Oct 23, 2021 at 9:56

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

ok yeah, makes sense

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.