- 积分
- 129
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2023-3-12
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 6 21:47:11 2023
画图:子图,双y轴图,散点图
@author: hp
"""
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib.ticker as ticker
#只能读入英文文件名称,,df[列号][行号]
file_name1=r"C:\Users\hp\Desktop\2022_related\namco_data_hourily_observation.xlsx"
file_name2=r"C:\Users\hp\Desktop\2022_related\namco_data_daily_change2.xlsx"
#读取第2个sheet:MAAP日综合变化
df1=pd.read_excel(file_name1,sheet_name=2,header=None,names=None)
df2=pd.read_excel(file_name2,sheet_name=5,header=None,names=None)
plt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示
plt.rcParams['axes.unicode_minus'] = False #解决符号无法显示
#横坐标改成*月*日*时,8月5号23时-9月11号15点
df_raw=df1[0][21:902]
df_bc=df2[1][2:883]
df_RA=df1[13][21:902]
list_time=[0]*len(df_raw)
for i in range(21,902):
list_time[i-21]=datetime.strptime(str(df_raw[i]),"%Y/%m/%d %H").strftime("%m/%d/%H时")
#不共享X轴:
fig, (ax1, ax2) = plt.subplots(2, sharex=True, figsize=(15,8))
ax1.plot(list_time,df_bc,label="")
plt.gca().xaxis.set_major_locator(ticker.MultipleLocator(110))
ax1.legend(loc=4,fontsize=20)
ax1.set_ylabel("黑炭浓度/(ng/m$^3$)",fontsize=20)
ax1.grid(True)
ax1.set_title("黑炭浓度变化与降水",fontsize=25)
ax1.tick_params(axis='x',labelsize=15) #刻度值字体大小设置,x轴y轴同时设置
#不能画出散点图和折线图在同一图来
ax2.scatter(list_time,df_RA,label="降水",c=df_RA,marker='.',linewidths=df_RA*8)
ax2_list=[0.1]*len(list_time)
ax2.plot(list_time,ax2_list,c='r',linewidth=2.5,linestyle='--')
ax2.annotate('降水阈值0.1mm',xy=(0,0.1),xytext=(0,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('P1',xy=(145,0.1),xytext=(145,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('P2',xy=(209,0.1),xytext=(209,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('',xy=(232,0.1),xytext=(209,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('P3',xy=(260,0.1),xytext=(260,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('P4',xy=(427,0.1),xytext=(427,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('P5',xy=(566,0.1),xytext=(566,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('P6',xy=(739,0.1),xytext=(739,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.annotate('P7',xy=(884,0.1),xytext=(884,3),fontsize=20,
arrowprops=dict(facecolor='red',shrink=0.01))
ax2.set_ylim(0,6)
ax2.legend(loc=1,fontsize=20)
ax2.set_ylabel("单小时降水/mm",fontsize=15)
ax2.grid(True)
ax2.tick_params(axis='x',labelsize=15) #刻度值字体大小设置,x轴y轴同时设置
ax2.tick_params(axis='y',labelsize=15)
plt.show()
|
|