在Python中的底图上重新绘制图
作者:互联网
我正在底图上绘制散点图.但是,具有此散点图的数据会根据用户输入而变化.我想清除数据(仅清除数据-而非整个底图),然后重新绘制新的散点图.
这个问题是相似的,但未得到回答(https://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()
然后,我重复以上所有代码. (我还必须为面板重做框大小调整器-我没有包括这些).
谢谢!
解决方法:
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 projections.
标签:scatter-plot,matplotlib-basemap,matplotlib,wxpython,python 来源: https://codeday.me/bug/20191101/1981663.html