0
我正在使用底圖和matplotlib的wx gui。我有兩個面板(左/右)。我在右圖中繪製了美國的地圖。這與下面的代碼沒有問題:wxpython和更新面板中的matplotlib圖
# 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()
此代碼設法清除我的右側面板並顯示新的地圖;但是,這張新地圖只位於面板的左上角。它不再延伸整個面板。任何想法,爲什麼這是?或者,有沒有更好的方法讓我清除底圖在同一個面板中繪製一個新的?
任何幫助,將不勝感激!謝謝!
我認爲您不需要重新創建Figure&FigureCanvas對象。嘗試註釋掉這兩行。 – HYRY 2012-08-09 00:27:33
就是這樣!我一直把頭撞在牆上,所以謝謝! – mcfly 2012-08-09 00:42:13