首先是设置副坐标轴的方法:
fig,ax1=plt.subplots() #subplots一定要带s
ax1.plot(x,data1,c='r')
ax1.set_ylabel('EXP')
ax2=ax1.twinx() #twinx将ax1的X轴共用与ax2,这步很重要
ax2.plot(x,data2,c='g')
ax2.set_ylabel('Log')
plt.show()
其实如果说把ax2设置为pandas下的数据类型比如dataframe或者series,很简单,如下:
df = pd.DataFrame(data)
fig,ax1=plt.subplots() #subplots一定要带s
ax1.plot(x,data1,c='r')
ax1.set_ylabel('EXP')
ax2=ax1.twinx() #twinx将ax1的X轴共用与ax2,这步很重要
#ax2.plot(x,data2,c='g')
df.plot(ax=ax2,c='g')
ax2.set_ylabel('Log')
plt.show()