0

我正在使用带有底图和 matplotlib 的 wx gui。我有两个面板(左/右)。我在右侧面板中绘制了一张美国地图。使用下面的代码没有问题:

# Setup the Map for Display
self.figure = Figure(None,dpi=75)
self.canvas = FigureCanvas(self.MapPage, -1, self.figure)
self.axes = self.figure.add_axes([0,0,1,1],frameon=False)
self.SetColor( (255,255,255) )  

#Sizer for Map Page Right Panel (Map Display)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.EXPAND | wx.ALL)
self.MapPage.SetSizer(sizer)

# Plot the Map
self.map = Basemap(llcrnrlon=-119, llcrnrlat=22, urcrnrlon=-64,
                   urcrnrlat=49, projection='lcc', lat_1=33, lat_2=45,
                   lon_0=-95, resolution='i', area_thresh=10000,ax=self.axes)
self.map.drawcoastlines()
self.map.drawcountries()
self.map.drawstates()

这就像一个魅力。但是,最终在代码的后面,我想将地图更改为可能只显示一个区域。这是我遇到问题的地方。目前,我正在这样做:

# Clear the previous figure
self.figure.clf()
self.figure.canvas.draw()

# Setup for the NEW Map to Display
self.figure = Figure(None,dpi=75)
self.canvas = FigureCanvas(self.MapPage, -1, self.figure)
self.axes = self.figure.add_axes([0,0,1,1],frameon=False)
self.SetColor( (255,255,255) )  

#Sizer for NEW Map Page Right Panel (Map Display)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.EXPAND | wx.ALL)
self.MapPage.SetSizer(sizer)

# Plot the NEW Map
self.map = Basemap(llcrnrlon=newlong1, llcrnrlat=newlat1, urcrnrlon=newlong2,
                   urcrnrlat=newlat2, projection='lcc', lat_0=maplat,
                   lon_0=maplon, resolution='i', area_thresh=10000,ax=self.axes)
self.map.drawcoastlines()
self.map.drawcountries()
self.map.drawstates()

此代码设法清除我的右侧面板并显示新地图;然而,这张新地图只在面板的左上角。它不再延伸到整个面板。关于为什么会这样的任何想法?还是有更好的方法让我清除底图图形以在同一面板中绘制新图形?

任何帮助,将不胜感激!谢谢!

4

0 回答 0