Guten Morgen alle zusammen, ich muss zu beginn Sagen, dass ich mit Python absolut unerfahren bin. Mal kurz meine Motivation: Durch ein Polynom 3ten Grades wird eine bestimmte Charakteristik visualisiert. Die Koeffizienten des Polynomes ändern sich immer nur minimal, so dass ein mittel-hochfrequentes (10-30Hz) Plotten des Polynoms mit aktualisierten Parametern eine "geschmeidige" Änderung des Graphen bewirkt. Ich suche nun eine Möglichkeit mit Python einen Plot zu erstellen, erster Versuch mit matplotlib ist daran gescheitert, dass man nach dem "show()" Befehl das Plot Fenster schließen muss um erneut im Eingabefenster zu landen, der "show()" Befehl hindert also ein autonomes refreshing durch mein Python Skript. Vielen Dank im voraus für eure Tipps und Hinweise. LG beginner
Ich hatte sowas mal mit IronPlot gemacht (weil ich wegen .NET DLLs mit IronPython arbeite). Vielleicht gibts da eine Entsprechung zum normalen Python? Dort ging das jedenfalls.
Das sollte ja wohl kein Problem sein -- google liefert weit oben dies: http://stackoverflow.com/questions/11764293/python-and-update-figure-in-matplotlib
Hallo, Dankeschön für eure Tipps... reichlich gegoogelt hatte ich natürlich auch schon die von dir empfohlene Seite Salewski behandelt leider nur "eventgesteuerte" Updates. Nichtsdestotrotz vielen Dank für deine Mühe Habe mittlerweile erfahren, das es eine matplotlib.animation library gibt die genau für diesen Anwendungsbereich gedacht ist (vergleichsweise sehr performant). Leider stehe ich nun vor einem erneuten Problem wo ich selbstständig trotz großer Bemühungen keine Lösung finden konnte. Und zwar soll bei bestimmten Bedingungen sich die Farbe des Plot Rahmens ändern. Ein Auszug aus dem Code ist hinzugefügt. Das funktioniert leider nur sporadisch bzw, scheinbar nur wenn ich mit der Maus über die Bereiche gehe (manchmal selbst dann nicht) vielleicht kennt sich ja hier jemand mit der Funktion aus?
1 | import socket |
2 | import matplotlib.animation as animation |
3 | from matplotlib.widgets import Button,MultiCursor |
4 | import pylab as py |
5 | |
6 | |
7 | fig = py.figure(1) |
8 | |
9 | ################################### |
10 | #Adds the first axis with settings# |
11 | ################################### |
12 | ax1 = fig.add_subplot(211,xlim=(-10, 50), ylim=(20, 120)) |
13 | dPredLine, = ax1.plot([],[]) |
14 | py.title('Prediction EcoRoll') |
15 | py.ylabel('d in [m]') |
16 | py.grid(True) |
17 | py.axvline(x=ERminTime, color='k', alpha=0.3) |
18 | py.axvline(x=0, color='k') |
19 | |
20 | #################################### |
21 | #Adds the second axis with settings# |
22 | #################################### |
23 | ax2 = py.subplot(212, xlim=(-10, 50), ylim=(-3, 3)) |
24 | vPredLine, = ax2.plot([],[]) |
25 | py.ylabel('v in [m/s]') |
26 | py.xlabel('time in [s]') |
27 | py.grid(True) |
28 | py.axvline(x=ERminTime, color='k', alpha=0.3) |
29 | py.axvline(x=0, color='k') |
30 | |
31 | |
32 | def init(): |
33 | ax2.yaxis.label.set_color('k') |
34 | ax2.spines['bottom'].set_color('k') |
35 | ax2.spines['top'].set_color('k') |
36 | ax2.spines['right'].set_color('k') |
37 | ax2.spines['left'].set_color('k') |
38 | ax1.yaxis.label.set_color('k') |
39 | ax1.spines['bottom'].set_color('k') |
40 | ax1.spines['top'].set_color('k') |
41 | ax1.spines['right'].set_color('k') |
42 | ax1.spines['left'].set_color('k') |
43 | return ax1, ax2 |
44 | |
45 | def animate_Pred(i): |
46 | if (ax1.yaxis.label.get_color() == 'g') and (ax2.yaxis.label.get_color() == 'g'): # if ER is active |
47 | print("ER active") |
48 | if (ndataList[5]<0): |
49 | set_ax1Color('r') |
50 | if (ndataList[7]<0): |
51 | set_ax2Color('r') |
52 | else: #ER is not active |
53 | if (ndataList[4]<6) or (ndataList[5]<6): #ER is not active because of d prediction |
54 | set_ax1Color('r') |
55 | print("dpred supress ER") |
56 | else: |
57 | set_ax1Color('g') |
58 | if (ndataList[6]<6) or (ndataList[7]<6): #ER is not active because of v rel prediction |
59 | set_ax2Color('r') |
60 | print("vrelPred supress ER") |
61 | else: |
62 | set_ax2Color('g') |
63 | return ax1, ax2 |
64 | |
65 | def set_ax1Color(c): |
66 | ax1.yaxis.label.set_color(c) |
67 | ax1.tick_params(axis='y', colors=c) |
68 | ax1.spines['bottom'].set_color(c) |
69 | ax1.spines['top'].set_color(c) |
70 | ax1.spines['right'].set_color(c) |
71 | ax1.spines['left'].set_color(c) |
72 | |
73 | def set_ax2Color(c): |
74 | ax2.yaxis.label.set_color(c) |
75 | ax2.tick_params(axis='y', colors=c) |
76 | ax2.spines['bottom'].set_color(c) |
77 | ax2.spines['top'].set_color(c) |
78 | ax2.spines['right'].set_color(c) |
79 | ax2.spines['left'].set_color(c) |
80 | |
81 | ani = animation.FuncAnimation(fig, animate_Pred, py.arange(1, 200), init_func=init, interval=40, blit=True) |
82 | |
83 | py.show() |
Du könntest vielleicht PyGame als Framework verwenden. Klingt zwar spielerisch, ist für dynamische Sachen aber ganz gut.
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
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.