- 积分
- 1038
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2022-4-5
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本人python小白,最近老师让尝试画一个污染物的浓度分布图,在查找资料和视频后,瞎鼓捣成下面这样。不太懂为什么背景图是紫色的,然后颜色填充的好像也不对,希望有大佬可以帮忙解答一下。
import xarray as xr
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
with open(r'D:\Users\hp\Desktop\2\CN-border-La.dat') as src:
context = src.read()
blocks = [cnt for cnt in context.split('>') if len(cnt) > 0]
borders = [np.fromstring(block, dtype=float, sep=' ') for block in blocks]
proj = ccrs.PlateCarree()
fig = plt.figure(figsize=(10,8),dpi=200)
ax = fig.add_axes([0.5,0.5,0.9,0.9], projection=proj)
ax.set_extent([97,132,17,47])
for line in borders:
ax.plot(line[0::2], line[1::2], '-', lw=1.5, color='k',
transform=ccrs.Geodetic())
ds = xr.open_dataset(r'D:\Users\hp\Desktop\1\ECHAP_PM10_V3.nc')
lon = ds.Lon
lat = ds.Lat
pm10 = ds.PM10
fig.canvas.draw()
cf = ax.contourf(lon,lat,pm10,transform=proj,camp='Spectral_r',aloha=0.8)
ax.set_xticks(np.arange(97,132,5))
ax.set_yticks(np.arange(17,47,5),crs=proj)
ax.xaxis.set_major_formatter(LONGITUDE_FORMATTER)
ax.yaxis.set_major_formatter(LATITUDE_FORMATTER)
fig.canvas.draw()
#设置刻度值,画经纬网格
xticks = [97,102,107,112,117,122,127]
yticks = [17,22,27,32,37,42,47]
ax.gridlines(xlocs=xticks, ylocs=yticks,linestyle='--',lw=1,color='dimgrey')
ax.coastlines()
ax.add_feature(cfeature.OCEAN.with_scale('50m'))
ax.add_feature(cfeature.LAND.with_scale('50m'))
plt.title('pm10浓度分布图')
plt.show()
|
-
|