我知道这个问题已经被问过很多次了。我已经阅读了相关的线程,并试图实现这些建议,但似乎什么都不起作用。图显示得很好,但保存它们会产生空白文件。
下面是我的代码:
for time_index in np.arange(hr_from,hr_to,1):
fig, ax = plt.subplots(figsize=[10, 10], subplot_kw={'projection': ccrs.PlateCarree()})
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=2, color='gray', alpha=0.5, linestyle='-')
extent = [-11, 16, 39, 61] # latitude and longitude borders of the map
ax.set_extent(extent)
#
# Other details of plotting omitted here
#
plt.rcParams['font.size'] = 12
ax.coastlines()
ax.add_feature(cartopy.feature.BORDERS)
fig.savefig("C:/maps.png", bbox_inches='tight')
我错过了什么?
编辑:如果有任何关联的话,输出文件类型是PapyrusPluginClass,我直到现在才听说过这个类,所以对它了解不多
1条答案
按热度按时间rqcrx0a61#
我不知道为什么,但我就是这么解决的:
在这行代码中,
图savefig(“C:/maps. png”,bbox_inches ='紧密')
我最初在里面有字符串,比如“%s”。我没有使用%s,而是使用了f-string,它开始正确地保存绘图。我完全没有预料到这会导致错误,这就是为什么我甚至没有像我最初在完整脚本中写的那样发布这一行。