- 积分
- 8
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2022-7-8
- 最后登录
- 1970-1-1

|
Python
系统平台: |
|
问题截图: |
- |
问题概况: |
在用matplotlib绘制特定地区年平均风速图时,发现绘制的图不全,只能看到行政区域线附近能看到一些颜色,但在学姐的电脑上的图是完整的,有大佬知道为什么会这样吗 |
我看过提问的智慧: |
看过 |
自己思考时长(天): |
1 |
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.ticker as cticker
import matplotlib.path as path
from cartopy.mpl.patch import geos_to_path
fig = plt.figure(figsize=(12,9))
proj = ccrs.PlateCarree()
leftlon,rightlon,lowerlat,upperlat = (73,135,3,53)
img_extent =[leftlon,rightlon,lowerlat,upperlat]
ax = fig.add_axes([0.1,0.1,0.8,0.6],projection = proj)
ax.set_extent(img_extent,crs =ccrs.PlateCarree())
ax.set_title("ERA5 monthly data on single levels from 2012 to 2021",fontsize=18)
ax.set_xlabel("Longitude",fontsize=14)
ax.set_ylabel("Latitude",fontsize=14)
ax.set_xticks(np.arange(leftlon,rightlon,10),crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(lowerlat,upperlat,10),crs=ccrs.PlateCarree())
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
position =fig.add_axes([0.72,0.1,0.015,0.6])#(分别是横坐标位置,纵坐标位置,色标宽度,色标长度)
c1 =ax.contourf(lons,lats,final,levels =np.arange(2,2.5,0.05),extend='both',cmap =plt.cm.Purples,transform=ccrs.PlateCarree())
fig.colorbar(c1,cax=position,orientation='vertical')
ax.add_feature(cfeature.COASTLINE,zorder=1)
#白化中国以外
shp = gpd.read_file(r'bou2_4l.shp',encoding='gbk')
# print(shp)
# 生成裁剪路径
path_clip = path.Path.make_compound_path(*geos_to_path(shp['geometry'].to_list()))
# 将裁剪路径应用到图层
[collection.set_clip_path(path_clip, transform=ax.transData) for collection in c1.collections]
# 绘制多边形边缘线
ax.add_geometries(shp['geometry'], crs=ccrs.PlateCarree(), facecolor='none', edgecolor='black')
plt.show()我用的是PyCharm,学姐用的是Python但我认为应该没有太大区别希望能有大佬指点迷津
|
-
这是在我的电脑上显示的图
|