【python】绘图集锦,python集锦,1、双Y轴,不同坐标
【python】绘图集锦,python集锦,1、双Y轴,不同坐标
1、双Y轴,不同坐标范围
1 def double_Y_axis(): 2 #sns.set_style("darkgrid") 3 4 without_rain = pd.read_csv("./data/s1201/S1201_2015_5_26.csv") 5 with_rain = pd.read_csv("./data/s1201/S1201_2016_5_25.csv") 6 7 y1_1= without_rain[‘TEMP‘] 8 y1_2 = without_rain[‘PRECIPITATIONAMOUNT‘] 9 x1 = without_rain[‘OBSTIME‘]10 11 y2_1 = with_rain[‘TEMP‘]12 y2_2 = with_rain[‘PRECIPITATIONAMOUNT‘]13 x2 = with_rain[‘OBSTIME‘]14 15 day_1 = [parser(x) for x in x1]16 day_2 = [parser(x) for x in x2]17 18 19 fig = plt.figure()20 ax1_1 = fig.add_subplot(211)21 ax2_1 = fig.add_subplot(212)22 23 ax1_2 = ax1_1.twinx()24 ax2_2 = ax2_1.twinx()25 26 ax1_1.plot(day_1 ,y1_1, ‘b‘,marker=‘o‘,label=‘temp‘)27 ax1_2.plot(day_1,y1_2,‘r‘,marker=‘o‘,label=‘precipitation‘) 28 29 ax2_1.plot(day_2 ,y2_1, ‘b‘,marker=‘o‘,label= ‘temp‘)30 ax2_2.plot(day_2,y2_2,‘r‘,marker=‘o‘,label = ‘precipitation‘) 31 32 hours = mdates.DateFormatter(‘%H:%M‘) 33 34 ax1_1.set_title("The temp variation without rain")35 ax1_1.set_ylabel(‘Y values for temp‘)36 ax1_2.set_ylabel(‘Y values for precipitation‘)37 ax1_2.set_ylim(-0.2,0.2,0.1)38 ax1_1.set_ylim(15,30)39 40 ax2_1.set_title("The temp variation with rain")41 ax2_1.set_ylabel(‘Y values for temp‘)42 ax2_2.set_ylabel(‘Y values for precipitation‘)43 ax1_1.xaxis.set_major_formatter(hours)44 ax2_1.xaxis.set_major_formatter(hours)45 ax1_1.grid(color = ‘#95a5a6‘)46 ax2_1.grid(color = ‘#95a5a6‘)47 48 ax1_1.legend()49 ax1_2.legend()50 51 plt.show()
显示:
【python】绘图集锦
相关内容
- 19、python基础学习-字符串及操作,, 1 #!/usr/
- python+opencv读取视频,调用摄像头,,引用import c
- Python: Tools,,在日常 python
- Python-图像处理库PIL图像变换transpose和transforms函数,,
- python-gevent模块实现socket大并发,,服务器端:geven
- python买卖股票的最佳时机--贪心/蛮力算法简介,python买
- Linux下安装Python3.5.2、Django、paramiko,,1,安装依赖文件:
- python3的Cryptodome,,简介python3的
- python 报错TypeError: 'range' object does not suppo
- python之路——作业:高级FTP(仅供参考),,一、作业需
评论关闭