爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 1793|回复: 0

[源代码] 设置绘图要素

[复制链接]

新浪微博达人勋

发表于 2023-6-4 20:02:12 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

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()






   








密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表