爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5537|回复: 0

[求助] 添加text后出现ValueError,提示图片太大

[复制链接]

新浪微博达人勋

发表于 2022-1-30 09:50:46 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
各位,我画图想添加text,没有添加之前图可以出,
ax.text(x=1,y=2,s='ss',fontdict=dict(fontsize=14,color='k',family='Simsun'),transform=ccrs.PlateCarree())
但是添加后只有提示错误:
ValueError: Image size of -558547720x386224160 pixels is too large. It must be less than 2^16 in each direction.我看了很多帖子感觉是ax设置的问题,但是不知道怎么修改。我把我画图的代码贴上来,大家帮忙看一下

#############作图########
proj=ccrs.LambertConformal() # 简写投影
plt.rcParams['font.sans-serif']=['SimHei']  #显示中文
fig=plt.figure(figsize=(14,9),dpi=300)#添加画布
ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  # 创建子图
extent=[107.5,110.0,33.638,34.76]#限定绘图范围
#隐藏边框线
plt.axis('off')
#tem_new[tem_new <0 ] = 0
#clevs = [0.1,2,4,6,8,10,15,20,25,50,100,250,500]
#cdict = ['#A9F090','#40B73F','#63B7FF','#0000FE','#FF00FC','#850042']
cmaps,clevs2 = meb.def_cmap_clevs(meb.cmaps.rain_1h)

# #裁切  添加地图,白化extent=[107.5,110.0,33.5,34.8]#限定绘图范围
blnfile ="D:/shp/bln.csv"
lines = maskout.getBJpolygon(blnfile)
ax  = boundary.addBoundary(blnfile,ax)
ext = [(107.5, 34.8), (107.5, 33.4), (110.0, 33.4), (110.0, 34.8),(107.5, 34.8)]
polygon2 = Polygon(ext,[lines])
ax.add_patch(PolygonPatch(polygon2, fc='white', ec='white', alpha=1, zorder=3 ))

shp_path=r'D:\shp\tt.shp'
a_shapes=list(Reader(shp_path).geometries())
#ax.add_geometries(a_shapes[:],crs=proj,edgecolor='k',facecolor='',lw=0.75)
reader = Reader(shp_path)
enshicity = cfeat.ShapelyFeature(reader.geometries(), proj, edgecolor='k', facecolor='none')
ax.add_feature(enshicity, linewidth=0.05)#添加市界细节
ax.set_extent(extent, crs=proj)

#ax.set_extent(extent, crs=proj)
#r = ax.scatter(lon,lat,c=(tem),s=10,cmap=cm.Greys)
contour = plt.contourf(lons[:,:],lats[:,:],rain[:,:],clevs2,cmap=cmaps)
#####图片text#####
ax.text(x=1,y=2,s='ss',fontdict=dict(fontsize=14,color='k',family='Simsun'),transform=ccrs.PlateCarree())
pos = fig.add_axes([0.55,0.23,0.31,0.035])   #位置[左,下,右,上]
cbar=plt.colorbar(contour,cax=pos,fraction=0.05,shrink=0.8,pad=0.23,orientation='horizontal')  
cbar.ax.tick_params(labelsize=15,size = 2,width = 0.1,pad=0.2,labeltop=True,labelbottom=False) #改变bar标签字体大小  pad 刻度线与刻度值之间的距离
#cbar.ax.set_title('(mm)',fontsize=11)
cbar.solids.set_rasterized(True)
cbar.solids.set_edgecolor("face")
cbar.outline.set_linewidth(0.05)  #cbar边框粗细
#pos.set_yticklabels((0.1,10,25,50,100,250,500))
#cbar.set_label(fontdict=1) #设置colorbar的标签字体及其大小
#标记站点
nameandstation={"1":[109.08,34.508],"1":[109.28,34.61],"3":[109.23,34.4],"4":[109.12,34.23],"5":[109.32,34.17],"6":[108.92,34.11],"7":[108.59,34.12],"8":[108.2,34.1],"9":[108.815,34.41]}
for key,value in nameandstation.items():
    ax.scatter(value[0] , value[1] , marker='.' , s=0.5 , color = "k" , zorder = 7)
    ax.text(value[0]-0.05 , value[1]+0.03 , key , fontsize =17, color = "k")
   
####添加市界外围#####
shp_path2=r'D:\shp\tt.shp'
a_shapes2=list(Reader(shp_path2).geometries())
#ax.add_geometries(a_shapes[:],crs=proj,edgecolor='k',facecolor='',lw=0.75)
reader2 = Reader(shp_path2)
enshicity2 = cfeat.ShapelyFeature(reader2.geometries(), proj, edgecolor='k', facecolor='none')
ax.add_feature(enshicity2, linewidth=1.8)#添加市界细节

   
plt.savefig(r'D:\test_data\picture\test.png',bbox_inches='tight')   ##保存图片,并让图片填充整个页面
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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