爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
楼主: edwardli

[经验总结] Python气象绘图Day-By-Day

  [复制链接]

新浪微博达人勋

发表于 2020-5-16 23:56:12 | 显示全部楼层
在哪里可以看到详细的内容啊?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-5-25 22:40:24 | 显示全部楼层
前辈你好,非常感谢你在优酷上有关python与气象的视频,对我帮助非常非常大(膜拜了)。
但还有一些地方没能搞懂(ps:我实在太菜了),所以希望能得到你视频(气象绘图7日速成)中演示所用的jupyter笔记。(求求了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-7-6 14:23:34 | 显示全部楼层
学习进度很快。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-7-6 20:58:36 | 显示全部楼层
楼主好厉害,正在学习中,谢谢楼主这么详细的解答
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-7-21 21:31:06 | 显示全部楼层
向大神学习学习!
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-8-13 22:06:35 | 显示全部楼层
楼主,我想看你micaps第一类数据站点的绘图,找不到你视频或者资源
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2020-9-3 09:43:58 | 显示全部楼层
郭小侠V 发表于 2020-8-13 22:06
楼主,我想看你micaps第一类数据站点的绘图,找不到你视频或者资源

"""
Spyder Editor

OLDLee.
"""
###引用部分
import numpy as np
import pandas as pd
from PIL import Image

from metpy.calc import wind_components
from metpy.plots import StationPlot
from metpy.plots.wx_symbols import current_weather, sky_cover
from metpy.units import units

import cartopy.crs as ccrs
import cartopy.feature as feat
import matplotlib.pyplot as plt
import cartopy.io.shapereader as shpreader

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
###打开文件,读取到名字为res的dataframe当中
#with open ("data.txt","w") as f:
#    f.write(a)


#a的值是全路径+文件名,用斜杠拆分,或者从右向左按位截取。
a=r"../Surf14090120.000"
#a=sys.argv[1]
#a=r'x:\surface\plot\19112420.000'
year='20'+a[-12:-10]
month=a[-10:-8]
day=a[-8:-6]
valid=a[-6:-4]


df=pd.read_csv(a,skiprows=3,header=None,encoding="GB2312",sep='\s+').drop([0])
df1=df.iloc[::2].reset_index(drop=True)
df2=df.iloc[1::2].reset_index(drop=True)
#for i in range(0,df.shape[0]):
#    if i%2==0:
#        df1=df1.append(df.iloc,ignore_index=True)
#    else:
#        df2=df2.append(df.iloc,ignore_index=True)
df1=df1.drop(columns=[12,13])
head=["stid","lon","lat","h","lev","cloud_fraction","wind_dir",
      "wind_speed","slp","p3","w1","w2","r6","lc","lcc","lch",
      "dew_point_temperature","vv","weather","air_temperature","mc","hc","s1","s2","T24","P24"]
res=pd.concat([df1,df2],axis=1,ignore_index=True)
res.columns=head
res[['stid','cloud_fraction','weather','w1','w2','lcc','lc','lch','mc','hc','p3','r6']]=res[['stid','cloud_fraction','weather','w1','w2','lcc','lc','lch','mc','hc','p3','r6']].astype('int')
res=res[res['stid']<80000]
res['weather']=res['weather'].replace(9999,0)
res['wind_speed']=res['wind_speed'].replace(9999,0)
res['weather']=res['weather'].astype('int')
res['cloud_fraction']=res['cloud_fraction'].replace(9999,10)
#res['slp']=res['slp'].replace(9999,np.NaN)
#res['r6']=res['r6'].replace(9999,0)
#res['p3']=res['p3'].replace(9999,0)
#all_data=res.loc[0:, ['stid','lat','lon','slp','air_temperature','cloud_fraction',
#                    'dew_point_temperature', 'weather','wind_dir','wind_speed']].values

#head=["stid","lon","lat","h","lev","cloud_fraction","wind_dir",
#      "wind_speed","slp","p3","w1","w2","r6","lc","lcc","lch",
#      "dew_point_temperature","vv","weather","air_temperature","mc","hc","s1","s2","T24","P24"]
res.to_csv('../station_data.txt', header=head, index=0, sep=" ")

all_data = np.loadtxt('station_data.txt', skiprows=1, delimiter=' ',
                      usecols=(0,2,1,8,19,5,16,18,6,7,9,12),
#                     usecols=(1, 3, 2,9,20,6,17,19,7,8),
                      dtype=np.dtype([('stid', '5S'), ('lat', 'f'), ('lon', 'f'),
                                      ('slp', 'f'), ('air_temperature', 'f'),
                                      ('cloud_fraction', 'f'), ('dew_point_temperature', 'f'),
                                      ('weather', '16S'),
                                      ('wind_dir', 'f'), ('wind_speed', 'f'),
                                      ('p3', 'f'), ('r6', 'f')]))

###########################################
# This sample data has *way* too many stations to plot all of them. Instead, we just select
# a few from around the U.S. and pull those out of the data file.

# Get the full list of stations in the data
#all_stids = [s.decode('ascii') for s in all_data['stid']]
all_stids = [s.decode('ascii') for s in all_data['stid']]

# Pull out these specific stations 白名单
#whitelist = ['OKC', 'ICT', 'GLD', 'MEM', 'BOS', 'MIA', 'MOB', 'ABQ', 'PHX', 'TTF',
#             'ORD', 'BIL', 'BIS', 'CPR', 'LAX', 'ATL', 'MSP', 'SLC', 'DFW', 'NYC', 'PHL',
#             'PIT', 'IND', 'OLY', 'SYR', 'LEX', 'CHS', 'TLH', 'HOU', 'GJT', 'LBB', 'LSV',
#             'GRB', 'CLT', 'LNK', 'DSM', 'BOI', 'FSD', 'RAP', 'RIC', 'JAN', 'HSV', 'CRW',
#             'SAT', 'BUY', '0CO', 'ZPC', 'VIH']

#whitelist = ['53276','54602','53798']
#MICAPS4当中一个时次文件导出的4级以上所有站点
#whitelist1=[50953,51463,52533,53513,54511,57083,56778,57516,57687,58362,59287,59431,51133,54102,59981,47420,47662,47936,47971,47991,50527,51828,55591,56739,56137,47058,47184,23921,23955,28900,30372,31168,31735,98429,44212,44292,30230,30710,35746,36870,42809,43128,22550,27612,24125,24959,38457,59997,48407,48455,24507,23552,28698,20069,20674,20744,20891,21824,42182,43333,91413,40754,57679,52889,48004,48037,98327,48845,48870,48848,51076,51288,51709,53463,53772,53915,54218,54337,54342,54823,57265,57461,57494,57816,58150,58238,58457,58606,58847,59316,59644,59758,50745,50774,51431,52203,52418,52681,53614,53646,53845,54161,54292,56029,57127,53898,56146,56444,56492,56571,57957,57993,58027,58633,58666,58725,59211,59265,59948,47412,47590,47600,47678,47740,47778,47909,47945,50353,50557,51644,51656,51886,52602,52754,52818,52836,53068,54135,54539,54662,54857,57297,47575,47927,50434,50727,52267,52323,53336,53391,54027,54776,56004,56046,55299,56964,57328,57745,58424,51711,57071,50983,56182,59007,51839,51855,54285,56986,55228,55664,55773,56312,56691,55472,56374,47025,47108,47115,47159,24641,28440,29231,29838,30673,30935,31004,31088,31329,31369,31416,31538,31866,31909,31960,32098,32150,32165,98223,98550,98618,98755,98836,44218,44231,44259,44272,44282,44304,44341,44354,44373,28838,28952,30309,35078,35394,35416,35671,35796,36003,36177,36428,38198,42361,42369,42867,43003,43014,43192,43237,43279,43284,22583,22845,26063,26298,26850,27595,27947,34009,34391,37018,37054,23804,24143,24343,24966,29612,29698,30758,32411,38062,38232,38413,38507,38880,38895,98526,22113,22271,22820,22887,26781,27037,33345,33393,33791,33837,33946,34560,34880,37472,58968,59559,59792,48042,48062,48327,48378,48500,24266,24329,24382,24688,24817,24908,24944,30054,30393,30433,30521,30554,30635,35700,35925,36061,38001,38353,38392,38613,38696,38750,1028,1055,1152,1384,1415,2186,2226,2836,2935,7149,7510,7650,7761,12375,13272,16560,42410,42634,42754,42886,42971,21802,23256,23330,23383,23472,23631,23678,23891,23966,25400,28064,28275,28493,28722,29263,29430,35121,38911,38954,38987,6011,6180,7110,11518,15420,15614,16420,16597,17060,17128,20087,20292,21432,21946,23205,25913,32389,32618,30777,36103,42071,42165,42571,42591,42623,43041,91245,91408,41660,41675,41620,41712,41715,41756,41768,41780,40362,40430,40582,40766,40800,40809,40821,40841,40848,40856,41024,41140,41150,40007,40712,41136,41196,41256,37985,48991,62387,63450,15120,17038,17050,17240,16754,60390,60590,26038,40650,2464,48354,60715,40394,40400,40405,40570,44221,44257,23418,91212,31054,62053,62062,62259,43149,48074,62271,42027,43150,98336,41936,62366,98446,98538,48840,48877,48887,48855,48866,48839,48838,51243,51573,52652,52866,53588,54401,54471,54497,56080,56096,58040,58221,58251,59117,59134,50136,50788,53564,53959,54094,54374,54423,54843,51379,51467,51495,53480,53698,54602,54725,54751,54916,57799,57866,58265,58472,58477,58527,59082,59293,59501,59663,59838,47401,47426,47582,47918,50756,50949,50978,51087,51156,52713,53276,57067,57245,47655,47800,47815,50603,50632,50915,51716,51777,51811,52495,53149,53192,53231,53529,53543,53723,54012,54026,54208,56033,56751,56786,57348,58834,59456,59493,59658,56951,57411,57447,57662,57972,58203,58314,59023,59417,59985,52737,52787,53352,53705,53863,54273,54863,56018,56021,50564,53487,53502,53923,54115,54157,54493,54945,57193,50658,50888,51053,51542,52436,52996,53083,54096,54527,54534,58562,58665,56671,57378,57598,57655,58321,58437,58569,58715,58731,58754,58911,59855,56144,56768,56838,56959,57731,57766,57922,59046,59072,50246,51232,52446,52825,56125,55248,55294,55437,56173,55578,56116,56172,56247,56462,56651,56985,57633,57902,55279,55696,56106,56385,56966,57237,57707,47008,47041,47165,30965,31371,31388,31510,31594,31707,98444,98630,44241,44277,44288,44298,44352,30844,31532,30949,98653,58974,59358,59158,48008,48110,48375,48431,48480,48930,48940,31832,51818,52957,53947,54906,54938,57016,58659,57713,57006,52118,54714,54616,44348,44386,30975,31445,31713,31801,98233,98553]
#原先挑选的部分站点
#whitelist1=[28044,28064,28382,28469,28642,28698,28879,28952,29231,29263,29282,29313,29557,29574,29612,29634,29789,29838,29846,29865,29999,30028,30054,30102,30230,30253,30309,30372,30393,30433,30469,30521,30554,30603,30635,30673,30692,30710,30758,30777,30823,30935,30949,30965,31004,31137,31168,31300,31329,31369,31416,31538,31735,31829,31873,31909,31960,35067,35358,35394,35576,35633,35796,36003,36061,36177,36259,36307,36428,36498,36729,36870,38049,38081,38198,38341,38413,38457,38613,44218,44231,44239,44241,44259,44272,44277,44282,44287,44288,44292,44298,44304,44305,44341,44347,44352,44354,44373,47025,47041,47058,47105,47108,47115,47159,47165,47184,47401,47412,47420,47575,47590,47600,47655,47662,47740,47778,47807,47827,47898,47909,47927,47936,47945,50353,50434,50527,50557,50603,50727,50745,50774,50788,50854,50915,50949,50953,50978,51076,51133,51243,51288,51431,51463,51495,51573,51644,51656,51709,51716,51765,51777,51828,51839,51855,51886,52203,52267,52323,52378,52418,52436,52446,52495,52533,52602,52633,52652,52681,52713,52754,52818,52836,52866,52889,52908,52957,53068,53083,53149,53192,53231,53276,53336,53391,53463,53480,53487,53513,53529,53543,53564,53588,53593,53614,53646,53698,53705,53723,53738,53764,53772,53798,53845,53898,53915,53923,53959,53975,54012,54026,54027,54102,54115,54135,54157,54161,54186,54208,54218,54226,54236,54259,54308,54311,54337,54342,54374,54401,54423,54436,54471,54497,54511,54527,54539,54587,54602,54616,54662,54714,54725,54753,54776,54808,54823,54843,54857,54906,54916,54938,56080,56096,56294,56492,57006,57036,57046,57067,57083,57127,57178,57193,57245,57259,57297,57328,57447,57461,57494,57516,57662,57687,57745,57799,57816,57957,57972,58027,58102,58150,58208,58221,58238,58362,58424,58457,58606,58633,58659,58725,58847,58921,59559,58968,59316,57993,59287,59265,59431,59211,59007,56778]
whitelist1=[28044,28064,28382,28469,28642,28698,28879,28952,29231,29263,29282,29313,29557,29574,29612,29634,29789,29838,29846,29865,29999,30028,30054,30102,30230,30253,30309,30372,30393,30433,30469,30521,30554,30603,30635,30673,30692,30710,30758,30777,30823,30935,30949,30965,31004,31137,31168,31300,31329,31369,31416,31538,31735,31829,31873,31909,31960,35067,35358,35394,35576,35633,35796,36003,36061,36177,36259,36307,36428,36498,36729,36870,38049,38081,38198,38341,38413,38457,38613,44218,44231,44239,44241,44259,44272,44277,44282,44287,44288,44292,44298,44304,44305,44341,44347,44352,44354,44373,47025,47041,47058,47105,47108,47115,47159,47165,47184,47401,47412,47420,47575,47590,47600,47655,47662,47740,47778,47807,47827,47898,47909,47927,47936,47945,50353,50434,50527,50557,50603,50727,50745,50774,50788,50854,50915,50949,50953,50978,51076,51133,51243,51288,51431,51463,51495,51573,51644,51656,51709,51716,51765,51777,51828,51839,51855,51886,52203,52267,52323,52378,52418,52436,52446,52495,52533,52602,52633,52652,52681,52713,52754,52818,52836,52866,52889,52908,52957,53068,53083,53149,53192,53231,53276,53336,53391,53463,53480,53487,53513,53529,53543,53564,53588,53593,53614,53646,53698,53705,53723,53738,53764,53772,53798,53845,53898,53915,53923,53959,53975,54012,54026,54027,54102,54115,54135,54157,54161,54186,54208,54218,54226,54236,54259,54308,54311,54337,54342,54374,54401,54423,54436,54471,54497,54511,54527,54539,54587,54602,54616,54662,54714,54725,54753,54776,54808,54823,54843,54857,54906,54916,54938,56080,56096,56294,56492,57006,57036,57046,57067,57083,57127,57178,57193,57245,57259,57297,57328,57447,57461,57494,57516,57662,57687,57745,57799,57816,57957,57972,58027,58102,58150,58208,58221,58238,58362,58424,58457,58606,58633,58659,58725,58847,58921,59559,58968,59316,57993,59287,59265,59431,59211,59007,56778,59431,59663,59758,59948,48930,48845,48855,42623,42591,42361,42027,38954,38911]
#whitelist1=[54398 ,54399 ,54406 ,54410 ,54412 ,54416 ,54419 ,54421 ,54424 ,54431 ,54433 ,54499 ,54501 ,54505,54511 ,54513 ,54514 ,54594 ,54596,54597 ,54428 ,54523 ,54525 ,54526 ,54527 ,54528 ,54529 ,54530 ,54619 ,54622 ,54623 ,54645 ,54646 ,53392 ,53397 ,53399 ,53491 ,53492 ,53498 ,53499 ,53593 ,53596 ,53599 ,53680 ,53682 ,53688 ,53689 ,53690 ,53691 ,53692 ,53693 ,53694 ,53695 ,53696 ,53697 ,53698 ,53699 ,53773 ,53781 ,53784 ,53785 ,53789 ,53790 ,53791 ,53792 ,53794 ,53795 ,53796 ,53797 ,53798 ,53799 ,53883 ,53886 ,53890 ,53891 ,53892 ,53893 ,53894 ,53895 ,53896 ,53897 ,53899 ,53980 ,53996 ,54301 ,54304 ,54308 ,54311 ,54318 ,54319 ,54401 ,54404 ,54405 ,54408 ,54420 ,54423 ,54425 ,54429 ,54430 ,54432 ,54434 ,54436 ,54437 ,54438 ,54439 ,54449 ,54502 ,54503 ,54506 ,54507 ,54510 ,54512 ,54515 ,54518 ,54519 ,54520 ,54521 ,54522 ,54531 ,54532 ,54533 ,54534 ,54535 ,54539 ,54540 ,54541 ,54601 ,54602 ,54603 ,54604 ,54605 ,54606 ,54607 ,54608 ,54609 ,54610 ,54611 ,54612 ,54613 ,54614 ,54615 ,54616 ,54617 ,54618 ,54620 ,54621 ,54624 ,54626 ,54627 ,54628 ,54631 ,54632 ,54633 ,54636 ,54640 ,54644 ,54700 ,54701 ,54702 ,54703 ,54704 ,54705 ,54706 ,54707 ,54708 ,54710 ,54711 ,54713 ,54717 ,54719 ,54800 ,54801 ,54804 ,54809 ,54820]
#with open('staion-level.txt','r') as f:
#        for line in f:
#                whitelist1.append(list(line.strip('\n').split('\t')))
#whitelist=whitelist1[0]
#whitelist.sort(reverse=False)
whitelist= list(set(whitelist1).intersection(set(res['stid'].values.tolist())))
whitelist2 = [str(i) for i in whitelist]
#for l in whitelist1:
#    if l not in res['stid'].values.tolist():
#        whitelist1.remove(l)
        
        

   
# Loop over all the whitelisted sites, grab the first data, and concatenate them
data = np.concatenate([all_data[all_stids.index(site)].reshape(1,) for site in whitelist2])

###########################################
# Now that we have the data we want, we need to perform some conversions:
#
# - Get a list of strings for the station IDs
# - Get wind components from speed and direction
# - Convert cloud fraction values to integer codes [0 - 8]
# - Map METAR weather codes to WMO codes for weather symbols

# Get all of the station IDs as a list of strings
stid = [s.decode('ascii') for s in data['stid']]

# Get the wind components, converting from m/s to knots as will be appropriate
# for the station plot

u, v = wind_components((data['wind_speed'] * units('m/s')),
                           data['wind_dir'] * units.degree)

# Convert the fraction value into a code of 0-8, which can be used to pull out
# the appropriate symbol
cloud_frac = (data['cloud_fraction']).astype(int)
p3 = data['p3']
p3[p3>999]=np.NaN
r6 = data['r6']
r6[r6>150]=np.NaN
r6[r6<=0]=np.NaN
# Map weather strings to WMO codes, which we can use to convert to symbols
# Only use the first symbol if there are multiple
wx_text = [s.decode('ascii') for s in data['weather']]
#wx_codes = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'10':10,
#            '11':11,'12':12,'13':13,'14':14,'15':15,'16':16,'17':17,'18':18,'19':19,'20':20,
#            '21':21,'22':22,'23':23,'24':24,'25':25,'26':26,'27':27,'28':28,'29':29,'30':30,
#            '31':31,'32':32,'33':33,'34':34,'35':35,'36':36,'37':37,'38':38,'39':39,'40':40,
#            '41':41,'42':42,'43':43,'44':44,'45':45,'46':46,'47':47,'48':48,'49':49,'50':50,
#            '51':51,'52':52,'53':53,'54':54,'55':55,'56':56,'57':57,'58':58,'59':59,'60':60,
#            '61':61,'62':62,'63':63,'64':64,'65':65,'66':66,'67':67,'68':68,'69':69,'70':70,
#            '71':71,'72':72,'73':73,'74':74,'75':75,'76':76,'77':77,'78':78,'79':79,'80':80,
#            '81':81,'82':82,'83':83,'84':84,'85':85,'86':86,'87':87,'88':88,'89':89,'90':90,
#            '91':91,'92':92,'93':93,'94':94,'95':95,'96':96,'97':97,'98':98,'99':99}
li=np.arange(0,100)
wx_codes = dict(zip(list(map(str,li)),li))
wx = [wx_codes[s.split()[0] if ' ' in s else s] for s in wx_text]
#wx=data['weather']

###########################################
# Now all the data wrangling is finished, just need to set up plotting and go
# Set up the map projection and set up a cartopy feature for state borders
proj = ccrs.PlateCarree()
#state_boundaries = feat.NaturalEarthFeature(category='cultural',
#                                            name='admin_1_states_provinces_lines',
#                                            scale='110m', facecolor='none')

###########################################
# The payoff
# ----------

# Change the DPI of the resulting figure. Higher DPI drastically improves the
# look of the text rendering
#####plt.rcParams['savefig.dpi'] = 255

# Create the figure and an axes set to the projection
fig = plt.figure(figsize=(20,14))
ax = fig.add_subplot(1, 1, 1, frameon=False,
                     projection=ccrs.LambertConformal(central_longitude=100,central_latitude=35.))
#projection=ccrs.PlateCarree())


#shpfilename = shpreader.natural_earth(resolution='110m',category='cultural',name='admin_0_countries')

# Add some various map elements to the plot to make it recognizable
#ax.add_feature(feat.LAND, zorder=-1)
#ax.add_feature(feat.OCEAN, zorder=-1)
ax.add_feature(feat.LAKES, zorder=1)
#ax.add_feature(feat.RIVERS, zorder=1)
#ax.add_feature(states_provinces, edgecolor='gray')
#ax.coastlines(resolution='110m', zorder=2, color='black')
#ax.add_feature(state_boundaries, edgecolor='black')
#ax.add_feature(feat.BORDERS, linewidth='2', edgecolor='black')
shpname=r'shp\NationalBorder.shp'
adm1_shapes=list(shpreader.Reader(shpname).geometries())
ax.add_geometries(adm1_shapes[:],ccrs.PlateCarree(),edgecolor='k',facecolor='',linewidth=0.8)    #36:72东三省
shpname=r'shp\hyd1_4l.shp'
adm1_shapes1=list(shpreader.Reader(shpname).geometries())
ax.add_geometries(adm1_shapes1[:],ccrs.PlateCarree(),edgecolor='b',facecolor='',linewidth=0.8)    #36:72东三省

####https://matplotlib.org/api/_as_g ... ib.axes.Axes.imshow

#fname = r'shp\NE1_HR_LC_SR.tif'
#img_extent = (-180, 180, -90,90)
#img = plt.imread(fname)
#ax.imshow(img, origin='upper', extent=img_extent, transform=ccrs.PlateCarree())
# Set plot bounds
#ax.set_extent((-118, -73, 23, 50))
ax.set_extent((75, 135, 15, 55))
#ax.set_extent((113, 120.5, 34.5, 45))
#
# Here's the actual station plot
#
# Start the station plot by specifying the axes to draw on, as well as the
# lon/lat of the stations (with transform). We also the fontsize to 12 pt.
stationplot = StationPlot(ax, data['lon'], data['lat'], transform=proj,fontsize=4.5)
#stationplot = StationPlot(ax, data['lon'], data['lat'], transform=ccrs.PlateCarree(), fontsize=4.5)

# Plot the temperature and dew point to the upper and lower left, respectively, of
# the center point. Each one uses a different color.
data['air_temperature'][data['air_temperature']>9000]=np.NaN
data['dew_point_temperature'][data['dew_point_temperature']>9000]=np.NaN
stationplot.plot_parameter('NW', data['air_temperature'], color='red',transform=proj)
stationplot.plot_parameter('SW', data['dew_point_temperature'], color='darkgreen',transform=proj)

# A more complex example uses a custom formatter to control how the sea-level pressure
# values are plotted. This uses the standard trailing 3-digits of the pressure value
# in tenths of millibars.
data['slp'][data['slp']>9000]=np.NaN
stationplot.plot_parameter('NE', data['slp'],
                           formatter=lambda v: format(1 * v, '.0f')[-4:],transform=proj)
stationplot.plot_parameter('E', data['p3'],transform=proj)
stationplot.plot_parameter('SE', r6,transform=proj)

# Plot the cloud cover symbols in the center location. This uses the codes made above and
# uses the `sky_cover` mapper to convert these values to font codes for the
# weather symbol font.
stationplot.plot_symbol('C', cloud_frac, sky_cover,transform=proj)

# Same this time, but plot current weather to the left of center, using the
# `current_weather` mapper to convert symbols to the right glyphs.
stationplot.plot_symbol((-1,0), wx, current_weather,transform=proj,fontsize=5)

# Add wind barbs
stationplot.plot_barb(u, v,transform=proj)
ax.gridlines(linestyle='--',
             xlocs=[60,70,80,90,100,110,120,130,140,150],
             ylocs=[10,20,30,40,50,60,70])
# Also plot the actual text of the station id. Instead of cardinal directions,
# plot further out by specifying a location of 2 increments in x and 0 in y.
stationplot.plot_text((2,-1), stid,transform=proj,fontsize=2.5)
#####绘制图层信息
#ax1 = fig.add_axes([0.5,0.5,3,3],frameon=False)
#plt.text(0.6,0.6,'14444444',fontsize=8)
rect = plt.Rectangle((-2650000,-1800000),1450000,850000,facecolor ='w',edgecolor='k',alpha=0.9)
ax.add_patch(rect)
ax.text(-2600000, -1100000,'地   面   天   气   图',fontsize=20)
ax.text(-2600000,-1300000,year+' 年 '+month+'月 '+day+'日 '+valid+'时',fontsize=20)
ax.text(-2600000,-1500000,'分析预报员:__________',fontsize=20)
#ax.text(-2600000,-1700000,'  曹 妃 甸 区 气 象 局〇',fontsize=18)
#ax.text(-1350000,-1690000,'c',fontsize=17)
#ax.background_img(name='BM', resolution='high',extent=[75, 135, 19, 58])
#####http://www.thomasguymer.co.uk/blog/2018/2018-01-15/
####http://earthpy.org/cartopy_backgroung.html
#####http://smellysheep.com/2019/03/% ... %E4%BD%9C%E5%9B%BE/
#####https://www.naturalearthdata.com ... 0m-natural-earth-1/   resample=True,
#ax.stock_img(name='ne_shaded')
Image.MAX_IMAGE_PIXELS = None
fname = r'shp\natural-earth-1_large8192px.png'
ax.imshow(plt.imread(fname), origin='upper', alpha=0.9,transform=ccrs.PlateCarree(),extent=[-180, 180, -90, 90])


#plt.savefig('D:\\天气图\\地面\\'+year+a[-10:-4]+'.png',dpi=600,transparent=False,bbox_inches='tight',frameon=False)
#plt.savefig('5.6.1-地面天气图.png',dpi=144,transparent=False,bbox_inches='tight',frameon=False)
   
plt.show()
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-1-16 08:01:54 | 显示全部楼层
大神,你的教材在哪里可以买得到啊,绘制探空图的代码和实例能分享一下吗
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-2-8 19:06:50 | 显示全部楼层
{:eb502:}{:eb502:}
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-2-14 13:05:40 | 显示全部楼层
楼主,请问一下探空图是怎么画的呀,我卡在底图那一组湿绝热线上了,(就是等假相当位温线,绿虚线),也找不到楼主讲探空图的帖子和视频,楼主给个链接或者文件呗,我想学习一下
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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