Python可视化 | 微波辐射计数据处理及可视化

2021-03-25 12:42:01 浏览数 (1)

这里先展示一下如何画微波辐射计的湿度时间剖面图吧。这个图只画了70%-100%范围,填色 等值线,用蓝绿色系,间隔为2,并且湿度越大,颜色越深。

下面的代码中,weibo_level_30.txt文件内容为微波辐射计的30个高度层,这里只画到3km的高度。另外一个txt文件为微波辐射计的数据文件。

这里推荐使用os.path.join命令来连接目录和文件名,用以规避多打或者少打斜杠的作用。

代码语言:javascript复制
import numpy as np
import pandas as pd
import os
from metpy import calc
from scipy import interpolate
import matplotlib.pyplot as plt 
from scipy.interpolate import Rbf
import cmaps

path_data = "./"
lvs   = np.loadtxt(os.path.join(path_data,"weibo_level_30.txt"))
data0 = np.loadtxt(os.path.join(path_data,"weibo_tc_zenith_RH_full.txt"))
data  = np.transpose(data0[:,4:34])
times = np.argwhere(data[0]!=-999)
x,y = np.meshgrid(times,lvs)
delete = np.argwhere(data[0]==-999)
data1 = np.delete(data,delete, axis=1)
title = 'Microwave Radiometer RH(unit: %)'
fig=plt.figure(figsize=(26,6))
plt.rc('font',size=15,weight='bold')
plt.title(title,size=25,weight='bold')
# 设置colorbar中颜色间隔个数
levels=np.linspace(60,100,21)
cf=plt.contourf(x,y,data1,levels=levels,cmap=cmaps.WhiteBlue)
cbar = plt.colorbar(cf)
cbar.set_label('RH (%)')  
cbar.set_ticks(np.linspace(60,100,11))
levels2 = np.arange(60,100,10)
line=plt.contour(x,y,data1,levels=levels2,colors='black')
fmt = {}
strs = ['60','70','80','90','100']
for l, s in zip(line.levels, strs):
    fmt[l] = s
plt.clabel(line,inline=True,fontsize=14,colors='black',fmt=fmt)
plt.xticks(np.arange(0,1441,60),['2412','2413','2414','2415','2416','2417','2418','2419','2420','2421','2422',
           '2423','2500','2501','2502','2503','2504','2505','2506','2507','2508','2509','2510','2511','2512'],rotation = 60)
plt.xlabel("Time (BJT)",fontsize=14)
plt.ylabel("Height (km)",fontsize=14)
#plt.xticks(np.arange(0,2881,120),['2400','2402','2404','2406','2408','2410','2412','2414','2416','2418','2420','2422','2500','2502','2504','2506','2508','2510','2512','2514','2516','2518','2520','2522'],rotation = 90)
#plt.yticks(nlines[0:8])    
plt.savefig("TC_RH.png",dpi=300)

出图效果如下:

0 人点赞