Pyplot等高线图-clabel间距 [英] Pyplot contour plot - clabel spacing
本文介绍了Pyplot等高线图-clabel间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用matplotlib/pyplot/basemap时遇到麻烦.我在地图上绘制轮廓线(气压).我使用clabel显示轮廓线的值. 但是问题是:值和轮廓线之间的填充过多.我发现参数"inline_spacing"已设置为零.但是仍然有很多可用空间.有什么想法吗?
I have trouble with matplotlib / pyplot / basemap. I plot contour lines (air pressure) on a map. I use clabel to show the value of the contour lines. But the problem is: the padding between the value and the contour line is too much. I have found the parameter "inline_spacing", which i have set to zero. But there is still to much free space. Any ideas?
Python代码:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import pygrib
filename = "file.grib2"
grbs = pygrib.open('/data/' + filename)
grb = grbs[2]
data = grb.values
datac = data*0.01
lats, lons = grb.latlons()
fig = plt.figure()
m = Basemap(projection='stere',lon_0=5,lat_0=90.0,\
llcrnrlon=-25.0,urcrnrlon=60.0,llcrnrlat=30.0,urcrnrlat=60.0,resolution='l')
x, y = m(lons, lats)
levs = range(940,1065,5)
S1=plt.contour(x,y,datac,levs,linewidths=0.5,colors='b')
plt.clabel(S1,inline=1,inline_spacing=0,fontsize=8,fmt='%1.0f',colors='b')
m.drawmapboundary(fill_color='w')
m.drawcoastlines(linewidth=0.2)
plt.savefig('test.png', bbox_inches='tight',pad_inches=0.05, dpi=100)
谢谢.
推荐答案
cb = plt.clabel(S1,inline=1,inline_spacing=0,fontsize=8,fmt='%1.0f',colors='b')
[txt.set_bbox(dict(boxstyle='square,pad=0',fc='red')) for txt in cb]
Matplotlib文本类创建一个bbox.您需要设置pad = 0
.然后inline_spacing
起作用.
Matplotlib Text class create a bbox. You need to set the pad = 0
.Then inline_spacing
works.
请参阅问题!
这篇关于Pyplot等高线图-clabel间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文