【发布时间】:2022-09-24 00:28:32
【问题描述】:
我在 python 中使用 Geopandas 和 matplotlib 创建了一张世界地图。当我尝试突出显示某个国家/地区时,地图尺寸会发生变化。如何保留地图尺寸?
import matplotlib
from matplotlib import pyplot
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.collections import PatchCollection
from matplotlib.figure import Figure
import geopandas as gpd
import pandas
self.figure = Figure()
self.canvas = FigureCanvas(self, -1, self.figure)
self.axes = self.figure.add_axes([0, 0, 1, 1])
self.axes.margins(0.0)
self.world_data = gpd.read_file(WORLD)
self.axes.clear()
self.axes.axis(\'off\')
self.figure.set_facecolor(WATER)
self.map_plot = self.world_data.to_crs(epsg=4326).plot(ax=self.axes, color=LAND)
if country_highlight:
self.world_data[self.world_data.ISO_A2_EH ==country_code].plot(edgecolor=u\'gray\', color=\'#fa8a48\', ax=self.map_plot)
self.canvas.draw()
标签: python pandas matplotlib geopandas