Programming/python(파이썬)
matplotlib animation
구차니
2024. 2. 28. 19:42
[링크 : https://matplotlib.org/stable/api/animation_api.html]
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation fig, ax = plt.subplots() xdata, ydata = [], [] ln, = plt.plot([], [], 'ro') def init(): ax.set_xlim(0, 2*np.pi) ax.set_ylim(-1, 1) return ln, def update(frame): xdata.append(frame) ydata.append(np.sin(frame)) ln.set_data(xdata, ydata) return ln, ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128), init_func=init, blit=True) plt.show() |
[링크 : https://pythonprogramming.net/python-matplotlib-live-updating-graphs/]
[링크 : https://stackoverflow.com/questions/11874767/how-do-i-plot-in-real-time-in-a-while-loop]
+ 2024.03.14
import cv2 import matplotlib.pyplot as plt def grab_frame(cap): ret,frame = cap.read() return cv2.cvtColor(frame,cv2.COLOR_BGR2RGB) #Initiate the two cameras cap1 = cv2.VideoCapture(0) cap2 = cv2.VideoCapture(1) #create two subplots ax1 = plt.subplot(1,2,1) ax2 = plt.subplot(1,2,2) #create two image plots im1 = ax1.imshow(grab_frame(cap1)) im2 = ax2.imshow(grab_frame(cap2)) plt.ion() while True: im1.set_data(grab_frame(cap1)) im2.set_data(grab_frame(cap2)) plt.pause(0.2) plt.ioff() # due to infinite loop, this gets never called. plt.show() |
[링크 : https://stackoverflow.com/questions/44598124/update-frame-in-matplotlib-with-live-camera-preview]
matplotlib.pyplot.ion()[source] Enable interactive mode. See pyplot.isinteractive for more details. See also ioff Disable interactive mode. isinteractive Whether interactive mode is enabled. show Show all figures (and maybe block). pause Show all figures, and block for a time. |
[링크 : https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.ion.html]