3

我正在底图上绘制散点图。但是,具有此散点图的数据会根据用户输入而变化。我想清除数据(只有数据——不是整个底图)并重新绘制新的散点。

这个问题很相似,但没有得到回答(http://stackoverflow.com/questions/8429693/python-copy-basemap-or-remove-data-from-figure)

目前我正在用 clf(); 但是,这需要我重新绘制整个底图和散点图。最重要的是,我正在 wx 面板内进行所有重绘。底图重绘需要太长时间,我希望有一种简单的方法可以简单地重新绘制散点。

#Setting up Map Figure 
self.figure = Figure(None,dpi=75) 
self.canvas = FigureCanvas(self.PlotPanel, -1, self.figure) 
self.axes = self.figure.add_axes([0,0,1,1],frameon=False) 
self.SetColor( (255,255,255) ) 

#Basemap Setup 
self.map = Basemap(llcrnrlon=-119, llcrnrlat=22, urcrnrlon=-64, 
                urcrnrlat=49, projection='lcc', lat_1=33, lat_2=45, 
                lon_0=-95, resolution='h', area_thresh=10000,ax=self.axes) 
self.map.drawcoastlines() 
self.map.drawcountries() 
self.map.drawstates() 
self.figure.canvas.draw() 

#Set up Scatter Plot 
m = Basemap(llcrnrlon=-119, llcrnrlat=22, urcrnrlon=-64, 
        urcrnrlat=49, projection='lcc', lat_1=33, lat_2=45, 
        lon_0=-95, resolution='h', area_thresh=10000,ax=self.axes) 

x,y=m(Long,Lat) 

#Scatter Plot (they plot the same thing) 
self.map.plot(x,y,'ro') 
self.map.scatter(x,y,90) 

self.figure.canvas.draw() 

然后我对我的 (x,y) 进行某种类型的更新...

#Clear the Basemap and scatter plot figures
self.figure.clf()

然后我重复上面的所有代码。(我还必须为我的面板重做我的盒子尺寸器——我没有包括这些)。

谢谢!

4

2 回答 2

4

matplotlib.pyplot.plot文档提到 plot() 命令返回具有 xdata 和 ydata 属性的Line2D 艺术家,因此您可以执行以下操作:

# When plotting initially, save the handle
plot_handle, = self.map.plot(x,y,'ro') 
...

# When changing the data, change the xdata and ydata and redraw
plot_handle.set_ydata(new_y)
plot_handle.set_xdata(new_x)
self.figure.canvas.draw()

不幸的是,我还没有设法让上述内容适用于收藏或3d 投影

于 2012-06-23T18:48:13.153 回答
0

大多数绘图函数返回Collections对象。如果是这样,那么您可以使用remove()方法。在您的情况下,我会执行以下操作:

# Use the Basemap method for plotting
points = m.scatter(x,y,marker='o')
some_function_before_remove()

points.remove()
于 2015-04-16T14:45:25.193 回答