2016-09-23 6 views
0

matplotlib의 애니메이션 모듈을 사용하여 실시간 스 캐터 - 종류 플롯을 만들려고 노력하고 있습니다. 그러나 나는 그걸 상당히 신참입니다. 내 목표는 내가 음모를 꾸미고 싶은 데이터를 수신 할 때마다 음모를 업데이트하여 데이터가 수신 될 때마다 이전의 점이 사라지고 새로운 점이 그려지도록하는 것입니다.애니메이션으로 스 캐터 업데이트

나는 무한 루프 및 데이터의 임의의 세대 수신 데이터로 대체하면 내 프로그램은 다음과 같이 쓸 수있다 :

> Traceback (most recent call last): 
    File "./skyplot.py", line 138, in <module> 
    ani= animation.FuncAnimation(fig, sat_plot.update, azimuths, elevations, colors) 
    File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 442, in __init__ 
    TimedAnimation.__init__(self, fig, **kwargs) 
    File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 304, in __init__ 
    Animation.__init__(self, fig, event_source=event_source, *args, **kwargs) 
    File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 53, in __init__ 
    self._init_draw() 
    File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 469, in _init_draw 
    self._drawn_artists = self._init_func() 
TypeError: 'list' object is not callable 
: 지금
fig = plt.figure() 
skyplot = fig.add_subplot(111, projection='polar') 
skyplot.set_ylim(90) # sets radius of the circle to maximum elevation 
skyplot.set_theta_zero_location("N") # sets 0(deg) to North 
skyplot.set_theta_direction(-1) # sets plot clockwise 
skyplot.set_yticks(range(0, 90, 30)) # sets 3 concentric circles 
skyplot.set_yticklabels(map(str, range(90, 0, -30))) # reverse labels 
plt.ion() 

while(1): 

    azimuths = random.sample(range(360), 8) 
    elevations = random.sample(range(90), 8) 
    colors = numpy.random.rand(3,1) 

    sat_plot = satellite() 
    ani= animation.FuncAnimation(fig, sat_plot.update, azimuths, elevations, colors) 

class satellite: 

    def __init__(self): 
     self.azimuths = [] 
     self.elevations = [] 
     self.colors = [] 
     self.scatter = plt.scatter(self.azimuths, self.elevations, self.colors) 

    def update(self, azimuth, elevation, colors): 
     self.azimuths = azimuth 
     self.elevations = elevation 
     return self.scatter 

, 나는 다음과 같은 오류를 받고 있어요을

누구나 내가 뭘 잘못하고 있는지 어떻게 알 수 있습니까? 어떻게해야합니까?

미리 감사드립니다.

+0

'FuncAnimation'을 (를) 사용하고 있는지 확실하지 않습니다. 'FuncAnimation (fig, sat_plot.update, fargs = (방위각, 고도, 색))'과 같이 호출해서는 안됩니다. –

답변

0

저는 애니메이션이 필요 없다고 생각합니다. 스레드에서 플롯을 업데이트하는 간단한 무한 루프 (예 : while)가 필요합니다. 다음과 같이 제안 할 수 있습니다.

import threading,time 
import matplotlib.pyplot as plt 
import numpy as np 

fig = plt.figure() 
data = np.random.uniform(0, 1, (5, 3)) 
plt.scatter(data[:, 0], data[:,1],data[:, 2]*50) 

def getDataAndUpdate(): 
    while True: 
     """update data and redraw function""" 
     new_data = np.random.uniform(0, 1, (5, 3)) 
     time.sleep(1) 
     plt.clf() 
     plt.scatter(new_data[:, 0], new_data[:, 1], new_data[:, 2] * 50) 
     plt.draw() 

t = threading.Thread(target=getDataAndUpdate) 
t.start() 
plt.show() 

결과는 산점도가있는 애니메이션과 같습니다.

+0

답변을 주셔서 감사합니다. 그러나 저는 캔버스 사용을 피하고 싶습니다. 내가 어떻게 할 수 있니? – paulzaba

+0

캔버스를 사용하고 싶지 않은 이유를 모르겠지만 'plt.clf()'및 'plt.draw()'가있는 솔루션이 있습니다. 새로운 코드를보십시오. –

관련 문제