我正在使用带底图和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()
此代码设法清除右侧面板并显示新地图;但是,这张新地图仅位于面板的左上角。它不再延伸到整个面板。有关为什么会这样的想法?或者有更好的方法让我清除底图图形以在同一面板中绘制一个新图形?
任何帮助将不胜感激!谢谢!
答案 0 :(得分:0)
在评论中回答。请参阅HYRY回复