简体   繁体   中英

wxpython and updating matplotlib figure in panel

I am using a wx gui with basemap and matplotlib. I have two panels (left/right). I plot a map of the US in my right panel. This occurs no problem with the code below:

# 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()

This works like a charm. However, eventually later in the code I would like to change the map to maybe only show a region. This is where I run into issues. Currently, I am doing this:

# 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()

This code manages to clear my right panel and display the new map; HOWEVER, this new map is only in the top left corner of the panel. It no longer stretches across the entire panel. Any ideas on why this is? Or is there a better way for me to clear the Basemap figure to plot a new one in the same panel?

Any help would be appreciated! Thanks!

Answered in comments. Please see HYRY response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM