2017-11-14 24 views
1

私はkivyアプリにストリーミングデータで毎秒更新したいmatplotlibグラフを持っています。これまでのところ私は少し奇妙な行動をしています。これは、更新を行いますが、私は「KV」ファイルでは少しkivy.clockでKivyを更新するmatplotlibグラフ

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() 

私のウィンドウのサイズを変更する場合にのみ、私は私がplot機能を更新しています

Label: 
    text: app.root.classify_sample(data) 

RecycleView Viewclass

内の結果を表示するclassify_sampleを呼び出します Clock.schedule_interval(self.plot,1)私は画面上の出力を印刷していますが、プロットは catA, catB or catCの値が変更されたときに更新されません 私はちょうど私のアプリケーションウィンドウのサイズを変更すると更新されます enter image description here

enter image description here

enter image description here

また、matplotlibの以外のグラフを追加するための別の方法は何ですか?私はアンドロイドのためにこれをパッケージ化するときMatplotlibは動かないだろうか?

+0

どこでcatA、catB、catCの値を変更しますか? –

+0

@SPSPは、入力が与えられたときに呼び出す別の関数です。 catA、catB、Cの更新は、 'plot'関数の中で結果を出力しているときに正しく動作しています。 –

+0

コードを投稿してください –

答えて

0

私はかなりばかげたエラーを作り出していました。 plot関数のグラフを更新した後、私は実際にbar_canvas.draw()メソッドを呼び出していませんでした

関連する問題