티스토리 뷰
예.
x = np.arange(10)
y = np.random.rand(10)
line, = plt.plot(x,y)
line.set_data(x,np.random.rand(10))
plt.draw()
그러나 데이터 프레임을 확장하고 각 추가 작업은 아마도 메모리의 해당 프레임을 새 위치로 복사하기 때문에 플로팅 속도가 느려집니다. 데이터 프레임의 크기가 증가하면 복사 작업이 더 오래 걸립니다. 나는 인덱스를 반복하고 그 ( for ii in range(len(data)): line.set_data(x[:ii], y[:ii])
)
편집하다:
import numpy as np
import matplotlib.pyplot as plt; plt.ion()
import pandas as pd
n = 100
x = np.arange(n)
y = np.random.rand(n)
# I don't get the obsession with pandas...
df = pd.DataFrame(dict(time=x, value=y))
# initialise plot and line
line, = plt.plot(df['time'], df['value'])
# simulate line drawing
for ii in range(len(df)):
line.set_data(df['time'][:ii], df['value'][:ii]) # couldn't be bothered to look up the proper way to index in pd
plt.draw()
plt.pause(0.001)
-------------------matplotlib의 라이브 플롯에 아래 코드를 사용할 수 있습니다.
import random
from itertools import count
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
plt.style.use('fivethirtyeight')
x_vals = []
y_vals = []
index = count()
def analyse(i):
data = pd.read_csv(<your file which is updated or live data>)#u can use the pandas or any other data frame work
x = data['index']
y1 = data['readings']
plt.cla()
plt.plot(x, y1, label='Temperature') #in my case data is temperature
plt.legend(loc='upper left')
plt.tight_layout()
ani = FuncAnimation(plt.gcf(), analyse, interval=1000) #adjust intervals for call
plt.tight_layout()
plt.show()
출처
https://stackoverflow.com/questions/39916933
댓글