我遇到了一些关于底图的问题,当我想尝试平移或缩放地图时,我会重新绘制地图。在这种情况下谁可以给我一些线索或方法?这是我包含的一些代码。谢谢 (我很抱歉我的英语不好)
main.py
from toolbar import tool_bar
from mapping import CanvasFrame
class MainWindow(object):
def __init__(self):
....
self.create_basemap()
def create_basemap(self):
self.canvas = CanvasFrame()
....
self.toolbar = tool_bar(self.canvas, self.window)
self.vbox1 = gtk.VBox(False, 2)
self.button1 = gtk.ToggleButton("zoom")
self.button1.connect("toggled", self.get_zoom)
self.button2 = gtk.ToggleButton("pan")
self.button2.connect("toggled", self.get_pan)
self.button3 = gtk.Button("restore")
self.button3.connect("clicked", self.get_restore)
self.vbox1.pack_start(self.button1)
self.vbox1.pack_start(self.button2)
self.vbox1.pack_start(self.button3)
....
def get_zoom(self, button):
if self.button1.get_active():
self.button2.set_active(False)
self.toolbar._zoom()
def get_pan(self, button):
if self.button2.get_active():
self.button1.set_active(False)
self.toolbar._pan()
def get_restore(self, button):
self.toolbar._restore()
....
mapping.py
from matplotlib.figure import Figure
from mpl_toolkits.basemap import Basemap
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
....
class CanvasFrame(FigureCanvas):
def __init__(self):
self.figure = Figure(dpi=80)
FigureCanvas.__init__(self, self.figure)
self.ax = self.figure.add_subplot(111)
self.plot_map()
def plot_map(self):
self.map = Basemap(projection = 'mill', resolution = 'i', llcrnrlon = 103.5,
llcrnrlat= -6.25,urcrnrlon = 107, urcrnrlat = -3.7, ax = self.ax)
....
toolbar.py
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg
class tool_bar(NavigationToolbar2GTKAgg):
def __init__(self, canvas, window):
super(NavigationToolbar2GTKAgg, self).__init__(canvas, window)
def _zoom(self):
self.zoom()
def _pan(self):
self.pan()
def _restore(self):
self.home()