- 积分
- 1429
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-3-26
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我在利用python绘制假相当位温时间序列图时显示不全,图片前半部分显示正常,但是后面像是被橡皮擦过了一样,线条也很奇怪。如下图,1508之前都很正常,后面就很奇怪。
但是我用别的数据出图就很正常,这两张图只是把数据路径改了下而已,这个问题困扰我很久了,数据也下载过很多次,是没错的。
用别的数据正常出的图
代码:
import xarray as xr
import pandas as pd
import numpy as np
import datetime as dt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.ticker as cticker
import matplotlib.pyplot as plt
import math
import datetime as dt
import matplotlib.dates as mdate
######计算假相当位温######
f_t=xr.open_dataset(r'/mnt/d/pythondata/meihua/t/1.nc')
f_rhu=xr.open_dataset(r'/mnt/d/pythondata/meihua/rhu/1.nc')
#time=f_t['time'].loc['2022-09-14T18':'2022-09-15T18']
time=f_t['time']
t=f_t['t']
Rh=f_rhu['r']
lat=f_t.latitude
lon=f_t.longitude
level=f_t['level']
#计算假相当位温
#Rh:相对湿度(%)|t:温度(K)|p:气压值(hPa)|nx:经向格点数|ny:纬向格点数
t0 = 273.16
e0 = 6.1078
L0 = 2500.79
cl = 2.3697
cpd = 1.0048
Rd = 0.28704
Rw = 0.4615
p=level##自己加的
nx=5
ny=5
#11个变量统一初始化成11个(ny,nx)二维数组
cttd,Ftd,tc,Lc,thetad,wc,thetase,Ltd,ttd,lew,ee = np.ones((11,ny,nx))
lew = 6.112*(np.e**((17.67*t)/(t+243.5)))
ee = ((lew*Rh)/100)/6.112
ttd = (243.5*(np.log(ee)))/(17.67-np.log(ee))
Ltd = L0-cl*(ttd-t0)
cttd = e0*((t0/ttd)**(cl/Rw))*(np.e**((L0+cl*t0)*(ttd-t0)/(Rw*ttd*t0)))
Ftd = (0.622*Ltd/(cpd*ttd))-1
tc = ttd*Ftd/(Ftd+np.log(ttd/t))
Lc = L0-cl*(tc-t0)
thetad = t*((1000.0/(p-cttd))**(Rd/cpd))
wc = 0.622*cttd/(p-cttd)
thetase = thetad*(np.e**(wc*Lc/(cpd*tc)))
thetase=thetase-273.15
#level为高空到低空(数值小到大),纬度北半球数值为高纬到低纬
thetase=thetase.loc[:,300:1000,31:29,121:123]
thetase=np.array(thetase).mean((2,3))#mean((2,3))表示对第2,3维求平均,一共0,1,2,3维
######计算假相当位温######
########绘图#####
fig=plt.figure(figsize=(3,3),dpi=300)
ax=fig.add_axes([0,0,0.5,0.5])
#先通过pandas.to_datetime()命令将时间转换为DatetimeIndex的格式,再通过strftime('%m%d%H')命令输出即可
timee=pd.to_datetime(time.time).strftime("%d%H").values
#设置边框粗细
ax.spines['bottom'].set_linewidth('0.5')
ax.spines['top'].set_linewidth('0.5')
ax.spines['left'].set_linewidth('0.5')
ax.spines['right'].set_linewidth('0.5')
#设置刻度长短、粗细
ax.tick_params(length=2,width=0.5)
ax.set_yscale('symlog')#将y变为对数坐标轴
ax.set_yticks([1000,925,850,700,500,400,300])
ax.set_xticklabels(['1308','1314','1320','1402','1408','1414','1420','1502','1508','1514','1520','1602'],fontsize=3)
ax.set_yticklabels(['1000','925','850','700','500','400','300'],fontsize=3)
ax.invert_yaxis() #翻转坐标轴
ax.set_xlabel('Time',fontsize=4)
ax.set_ylabel('p/hPa',fontsize=4)
c=ax.contour(timee,level,thetase.T,levels=np.arange(60,100,3),colors='k',linewidths=0.5)#.T表示转置,因为按照顺序x轴time,y轴level,thetase为相反
############ax.quiverkey(q,0.95,-0.1,30,'30 m/s',labelpos='S',labelsep=0.02,fontproperties={'size':3},coordinates='axes')
ax.clabel(c,fontsize=4)#显示等值线数值
#########绘图########
|
-
|