###前提・実現したいこと
matplotlibを用いてpandasの動的dataFrameをリアルタイム描画したい。
###発生している問題・エラーメッセージ
matplotlibを用いたグラフ作成を学習中なのですが、pandasの動的データのリアルタイム描画でつまずいています。
###該当のソースコード
Python
1import os, sys 2import pandas as pd 3import matplotlib.pyplot as plt 4 5sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) 6 7# use pandas 8def realtime_plot_pd(): 9 x = 0.1 10 df = pd.DataFrame([[x, 1], [1, 1]]).T 11 df.columns = ["Down", "up"] 12 df.index = ["One", "Two"] 13 df.plot(kind= "bar", stacked= True) 14 15 while True: 16 x = x + 0.1 17 new = pd.DataFrame([[x, 1], [1, 1]]).T 18 new.columns = ["Down", "up"] 19 new.index = ["One", "Two"] 20 df.update(new["Down"]) 21 print df 22 23 plt.pause(.1) 24 25realtime_plot_pd() 26 27# use bumpy 28def realtime_plot_np(): 29 left = np.array([1, 2]) 30 x = 0.1 31 height = np.array([x, 1]) 32 graph = plt.bar(left, height) 33 34 while True: 35 x = x + 0.1 36 height = np.array([x, 1]) 37 graph[0].set_height(height[0]) 38 plt.pause(.1) 39 40realtime_plot_np() 41
###試したこと
pandasでなくnumpyを使った場合はグラフに反映されるのですが、pandasの場合dataframe自体は更新してるぽいのですが、グラフに反映されません。どういうやり方があるのか、アドバイスをいただけたらと思います。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/24 23:58