从该代码处绘制wrf中的土地利用报错内容及其解决方法
1.报错内容:
微信公众平台 (qq.com)https://mp.weixin.qq.com/s/Cn0vhvfroVADPnT237LXNw
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[9], line 74 start(file_in,shp_path)6 if __name__ == "__main__": ----> 7 main()Cell In[9], line 4, in main()2 file_in = "F:/pythonplot/geo_em.d01.nc"3 shp_path = "F:/毕业数据处理/中国shp/3省市县行政区划界线/chinaProvince.shp" ----> 4 start(file_in,shp_path)Cell In[5], line 43, in start(file_in, shp_path)41 ax.xaxis.set_major_formatter(LONGITUDE_FORMATTER)42 ax.yaxis.set_major_formatter(LATITUDE_FORMATTER) ---> 43 lambert_xticks(ax, xticks)44 lambert_yticks(ax, yticks)46 # 叠加shpCell In[8], line 19, in lambert_xticks(ax, ticks)17 te = lambda xy: xy[0]18 lc = lambda t, n, b: np.vstack((np.zeros(n) + t, np.linspace(b[2], b[3], n))).T ---> 19 xticks, xticklabels = _lambert_ticks(ax, ticks, 'bottom', lc, te)20 ax.xaxis.tick_bottom()21 ax.set_xticks(xticks)Cell In[8], line 35, in _lambert_ticks(ax, ticks, tick_location, line_constructor, tick_extractor)33 def _lambert_ticks(ax, ticks, tick_location, line_constructor, tick_extractor):34 """Get the tick locations and labels for an axis of a Lambert Conformal projection.""" ---> 35 outline_patch = sgeom.LineString(ax.outline_patchs.get_path().vertices.tolist())36 axis = find_side(outline_patch, tick_location)37 n_steps = 30AttributeError: 'GeoAxes' object has no attribute 'outline_patch'
2.解决方法:
源代码:
def _lambert_ticks(ax, ticks, tick_location, line_constructor, tick_extractor):
"""Get the tick locations and labels for an axis of a Lambert Conformal projection."""
outline_patch = sgeom.LineString(ax.outline_patch.get_path().vertices.tolist())
axis = find_side(outline_patch, tick_location)
n_steps = 30
extent = ax.get_extent(ccrs.PlateCarree())
_ticks = []
for t in ticks:
xy = line_constructor(t, n_steps, extent)
proj_xyz = ax.projection.transform_points(ccrs.Geodetic(), xy[:, 0], xy[:, 1])
xyt = proj_xyz[..., :2]
ls = sgeom.LineString(xyt.tolist())
locs = axis.intersection(ls)
if not locs:
tick = [None]
else:
tick = tick_extractor(locs.xy)
_ticks.append(tick[0])
# Remove ticks that aren't visible:
ticklabels = copy(ticks)
while True:
try:
index = _ticks.index(None)
except ValueError:
break
_ticks.pop(index)
ticklabels.pop(index)
return _ticks, ticklabels
改变代码
def _lambert_ticks(ax, ticks, tick_location, line_constructor, tick_extractor):
"""Get the tick locations and labels for an axis of a Lambert Conformal projection."""
outline_patch = sgeom.LineString(ax.patch.get_path().vertices.tolist())
axis = find_side(outline_patch, tick_location)
n_steps = 30
extent = ax.get_extent(ccrs.PlateCarree())
_ticks = []
for t in ticks:
xy = line_constructor(t, n_steps, extent)
proj_xyz = ax.projection.transform_points(ccrs.Geodetic(), xy[:, 0], xy[:, 1])
xyt = proj_xyz[..., :2]
ls = sgeom.LineString(xyt.tolist())
locs = axis.intersection(ls)
if not locs:
tick = [None]
else:
tick = tick_extractor(locs.xy)
_ticks.append(tick[0])
# Remove ticks that aren't visible:
ticklabels = copy(ticks)
while True:
try:
index = _ticks.index(None)
except ValueError:
break
_ticks.pop(index)
ticklabels.pop(index)
return _ticks, ticklabels