본문 바로가기
python

chatGPT 로 real-time graph 그리기 matplotlib.animation

by 타닥타닥 토다토닥 부부 2023. 2. 15.
반응형

chatGPT 로 real-time graph 그리기 matplotlib.animation

 

코딩의 모르는 부분을 구글링이 아닌 chatGPT로 해결해 보고자 시도해 보았습니다. !

질문은 "make realtime chart with python" 이였습니다. 

 

chatGPT 가 추천해준 코드는 아래와 같습니다. 사실 코드가 안돌아가서 코드 하나만 수정하였습니다.

import matplotlib.pyplot as plt
import random
import matplotlib

# Set up the figure and axis
fig, ax = plt.subplots()
ax.set_xlim(0, 100)
ax.set_ylim(0, 1)

# Create an empty line object
line, = ax.plot([], [])

# Update function to update the line data
def update(i):
    x = list(range(i))
    y = [random.random() for _ in x]
    line.set_data(x, y)
    ax.relim()
    ax.autoscale_view()
    return line,

# Animate the chart
ani = matplotlib.animation.FuncAnimation(fig, update, frames=100, interval=100, blit=True)

# Show the chart
plt.show()

 

실행결과는 아래와 같습니다. 

 

 

반응형

댓글