Forum: Compiler & IDEs Python Fast Graph


von Christoph M. (mchris)


Lesenswert?

Wie kann man mit Python Daten von der seriellen Schnittstelle dynamisch 
schnell visualisieren?

Für dynamische Graphn soll man "FuncAnimation" verwenden. Hier mal ein 
Beispiel, das lustigerweise ein Art aliasing Effekt hat:
1
#!/python
2
3
import tkinter as tk
4
import matplotlib.pyplot as plt
5
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
6
from matplotlib.animation import FuncAnimation
7
import numpy as np
8
9
root = tk.Tk()
10
11
fig, ax = plt.subplots()
12
xdata, ydata = [], []
13
ln, = ax.plot([], [], 'b-')
14
15
def init():
16
    ax.set_xlim(0, 100)
17
    ax.set_ylim(-1, 1)
18
    return ln,
19
20
def update(frame):
21
    xdata.append(frame)
22
    ydata.append(np.sin(frame * 0.1))
23
    ln.set_data(xdata, ydata)
24
    ax.set_xlim(max(0, frame-99), frame)
25
    return ln,
26
27
canvas = FigureCanvasTkAgg(fig, master=root)
28
canvas.get_tk_widget().pack(fill=tk.BOTH, expand=True)
29
30
ani = FuncAnimation(fig, update, frames=np.arange(0, 1000),
31
                    init_func=init, blit=True, interval=50)
32
33
root.mainloop()

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.