LoginSignup
3
3

More than 5 years have passed since last update.

matplotlibを用いたリアルタイムプロット

Posted at

matplotlibは重すぎてアニメーションプロットに向いていない気がする。

以下の記事を参考に2変数をappendしていくlistをplotする例を書いた。
https://qiita.com/hausen6/items/b1b54f7325745ae43e47

subplotを使うのとplt.pauseが味噌。


pos = []
lines = []
while 1:
 # get some newdata=[x,y]
 pos.append(newdata)

 if not lines:
  fig, ax = plt.subplots(1,1)
  lines, = ax.plot([i[0] for i in pos],[i[1] for i in pos])
  ax.set_xlim((-1.5,1.5))
  ax.set_ylim((-1.5,1.5))
 else:
  lines.set_data([i[0] for i in pos],[i[1] for i in pos])

 plt.pause(0.001)
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3