ich ein matplotlib Graph in meiner Kivy app, die ich jede Sekunde mit Streaming-Daten aktualisieren möchten. Soweit habe ich mich etwas komisch verhalten. Es tut Update aber nur, wenn ich mein Fenster ein wenigKivy Update matplotlib Graph mit kivy.clock
fig, ax = plt.subplots()
width = 0.65
ax.set_title('Scores by group and gender')
bar_canvas = fig.canvas
class Test(BoxLayout):
catA = NumericProperty(0)
catB = NumericProperty(0)
catC = NumericProperty(0)
#plot the bar graph
def plot(self, dt):
catA_rects = ax.bar(5, self.catA, width, color='g')
catB_rects = ax.bar(6, self.catB, width, color='#808080')
catC_rects = ax.bar(7, self.catC, width, color='r')
ax.legend((catA_rects[0], catB_rects[0], catC_rects[0]), ('Category A', 'Category B', 'Category C'))
#update the graph
def update(self):
Clock.schedule_interval(self.plot,1)
def classify_sample(self, test_sample):
result_prob = classifier.predict_proba(test_sample)[0]
result = classifier.predict(test_sample)[0]
if result_prob.max() > 0.55:
if result == 1:
self.catA += 1
else:
self.catC += 1
else:
self.catB += 1
class ClassificationApp(App):
def build(self):
res = Test()
res.bar_tab.add_widget(bar_canvas)
res.update()
return res
if __name__ == '__main__':
ClassificationApp().run()
In ‚kv‘ Datei die Größe nenne ich classify_sample in einem RecycleView Viewclass
Label:
text: app.root.classify_sample(data)
die Ergebnisse anzuzeigen Ich bin Aktualisierung der plot
Funktion mit Clock.schedule_interval(self.plot,1)
das funktioniert, wenn ich die Ausgabe auf dem Bildschirm drucke, aber das Diagramm wird nicht aktualisiert, wenn der Wert catA, catB or catC
ändert Es wird nur aktualisiert, wenn ich die Größe meiner App ein kleines Fenster
Auch gibt es eine andere Art und Weise Diagramme anders als matplotlib hinzufügen? Matplotlib wird nicht funktionieren, wenn ich das für Android richtig verpacke?
aufgerufen wo ändern Sie die Werte von CatA, CatB und CatC? –
@SPSP in einer anderen Funktion, die ich bei der Eingabe anrufe. Die Aktualisierungen für catA, catB und C funktionieren ordnungsgemäß, wenn ich die Ergebnisse innerhalb der Plot-Funktion drucke. –
bitte posten mehr Code –