How to add legends (labels) and fix tight layout in a subplot with multiple plots

▼魔方 西西 提交于 2021-02-11 14:54:24

问题


I have the following code to generate a (2,2) gridspec subplots.

gs=GridSpec(2,2)
fig=plt.figure(figsize= (12,6))
ax1=fig.add_subplot(gs[0,0])
ax2=fig.add_subplot(gs[0,1]) 
ax3=fig.add_subplot(gs[1,:])

ax1.plot(df_wip[['CADUSD=X', 'INRUSD=X', 'PLNUSD=X']], label= ['CAD', 'INR', 'PLN'])
ax1.legend()
ax2.plot(df_wip[['BRLUSD=X', 'ZARUSD=X']])
ax2.set_xticks([])
ax3.plot(df_wip[['CL=F', 'GC=F', '^TNX']])
gs.tight_layout(fig)

See that the legends are not appropriate, and xticks are tight. How to fix them?

Much thanks.

来源:https://stackoverflow.com/questions/61495419/how-to-add-legends-labels-and-fix-tight-layout-in-a-subplot-with-multiple-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!