- 积分
- 939
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2019-12-8
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2020-1-16 15:28:50
|
显示全部楼层
还是说我的代码其他地方有问题?我是第一次用python绘制气象图片,可能有点坑
这是我完整代码
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
import cartopy.crs as crs
from cartopy.feature import NaturalEarthFeature
f=open(r'C:\Users\Administrator\Desktop\SURF_CLI_CHN_PRE_DAY_GRID_0.25-20190811.grd','r')
a=np.fromfile(f,dtype=np.float32)
f.close()
b=a.reshape(2,256,144)
rain=b[0,:,:]
for i in range(256):
for j in range(144):
if rain[i,j]==-999:
rain[i,j]=0
lon=72.125+0.25*np.arange(256)
lat=18.125+0.25*np.arange(144)
lat, lon = np.meshgrid(lat, lon)
fig = plt.figure(figsize=(12,6))
states = NaturalEarthFeature(category="cultural", scale="10m",
facecolor="none",
name="admin_1_states_provinces_shp")
ax = plt.axes(projection=crs.PlateCarree())
ax.add_feature(states, linewidth=.5, edgecolor="black")
ax.coastlines()
ax.gridlines(linestyle='--')
plt.contour(lon, lat, rain, 5, colors="black",transform=crs.PlateCarree())
plt.show() |
|