爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 3083|回复: 2

请教关于matplotlib出图不全的问题

[复制链接]

新浪微博达人勋

发表于 2022-7-25 15:15:21 | 显示全部楼层 |阅读模式
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但我认为应该没有太大区别希望能有大佬指点迷津

这是在我的电脑上显示的图

这是在我的电脑上显示的图
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2022-7-25 16:14:12 | 显示全部楼层
顺序问题吧
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2022-7-26 15:28:29 | 显示全部楼层
昨天请教了一下大佬,结果是需要跟白化的shp文件里面的编号对上,我之前用的是中国各省轮廓图,这次换了一个shp文件(为中国国家轮廓),可以正常出图了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表