我有两个子图,但我希望它们共享相同的公共Xlabel。每个子图都来自单独的数据帧。问题是,即使我使用了sharex=True,xlabels也不能被共享。每个子图都有自己的xlabel,来自dataframe列名。
代码:
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()发布于 2021-10-23 10:24:12
您是否预期会出现这样的结果:

如果是,您需要更正:
fig,ax = plt.subplots(1,2, sharex=True)出自:
fig,ax = plt.subplots(2,1, sharex=True)https://stackoverflow.com/questions/69686749
复制相似问题