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 に答える