关键函数: twinx()
import numpy as np
import matplotlib.pyplot as plt
**#设置随机数**
time=np.arange(10)
temp=np.random.random(10)*30
Swdown=np.random.random(10)*100-10
Rn=np.random.random(10)*100-10
fig=plt.figure(figsize=(10,8))
ax=fig.add_subplot(1,1,1)
ax.plot(time,Swdown,'-',alpha=.5,label='Swdown')
ax.plot(time,Rn,'-',label='Rn')
ax2=ax.twinx()
****#关键一步,建立ax2子图与ax同x轴****
ax2.plot(time,temp,'-r',label='temp')
ax.grid()
ax.set_xlabel('Time(h)')
ax.set_ylabel(r'Radiation($MJ,m^{-2},d^{-1}$)')
ax2.set_ylabel(r'Temperature($^circ$C)')
ax2.set_ylim(0,35)
ax.set_ylim(-20,100)
最后
以上就是含蓄小蝴蝶最近收集整理的关于matplotlib双y轴的全部内容,更多相关matplotlib双y轴内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复