[英]How to remove the frame of a matplotlib image and set background color to transparent
我怎樣才能去掉map的黑框? 是否可以將該框架內的背景顏色從白色更改為透明?
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
fname = 'germany.shp'
shapes = list(shpreader.Reader(fname).geometries())
ax = plt.axes(projection=ccrs.NorthPolarStereo(central_longitude=10.0))
ax.add_geometries(shapes, ccrs.PlateCarree(), edgecolor='none', alpha=1)
ax.set_facecolor((1.0, 0.47, 0.42))
ax.set_extent([6, 15, 47, 55])
plt.savefig("map.png", format='png', dpi=400, quality=95)
plt.show()
使用plt.axis('off')
軸並使用plt.savefig('name.png', transparent=True)
保存圖形透明。
編輯:要更改的邊框和背景由 cartopy GeoAxes 引入。 要更改它們,請使用:
ax.background_patch.set_visible(False) # Background
ax.outline_patch.set_visible(False) # Borders
可以在此處找到參考示例。
請注意,仍然需要plt.savefig
中的transparent=True
關鍵字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.