3

저는베이스 맵에 산점도를 플로팅하고 있습니다. 그러나이 산점도가있는 데이터는 사용자 입력을 기반으로 변경됩니다. 데이터 (전체 basemap 수치가 아닌 데이터 만)를 지우고 새로운 scatter point를 다시 그리기를 원합니다.파이썬에서베이스 맵의 플롯 다시 그리기

이 질문은 비슷하지만 (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() 

은 그 때 나는

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

그런 다음 나는 위의 모든 코드를 반복 ... 내 (X, Y)에 갱신의 몇 가지 유형을한다. (나는 또한 나의 패널을 위해 나의 상자 sizer를 다시해야한다 - 나는 그들을 포함시키지 않았다).

감사합니다.

+0

일부 코드를 게시 해주십시오. 산점도가 어떻게 그려지는지보고 싶습니다. – stanri

답변

4

matplotlib.pyplot.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.

+0

이것은 완벽하게 작동했습니다! 감사! – mcfly

+0

'plot_handle, = self.map.plot (x, y, 'ro')'의 등호 왼쪽에있는 쉼표의 목적이 무엇인지 설명 할 수 있습니까? 나는 그것이 필요하다는 것을 안다. 그러나 나는 이유를 모른다. –

+1

@KShores 튜플에서 첫 번째 요소의 압축을 풉니 다. http://stackoverflow.com/questions/1708292/meaning-of-using-commas-and-underscores-with-python-assignment-operator를 참조하십시오. – stanri

0

대부분의 플로팅 함수는 Collections 개체를 반환합니다. 그렇다면 remove() 방법을 사용할 수 있습니다. 귀하의 경우 다음을 수행합니다.

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

points.remove()