LoginSignup
0
0

More than 1 year has passed since last update.

Jupyter notebookでのmatplotlib animationの表示

Posted at

概要

Jupyter notebookで、%matplotlib inlineとしたときに、アニメーションが表示できなかったので、簡単にまとめる。

↓このページがとても美しくまとめてくださっている。
https://jckantor.github.io/CBE30338/A.03-Animation-in-Jupyter-Notebooks.html

環境

Python 3.10.0
matplotlib==3.5.2

詳細
$ python --version
Python 3.10.0
$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.4.0
ipykernel        : 6.13.0
ipywidgets       : not installed
jupyter_client   : 7.3.2
jupyter_core     : 4.10.0
jupyter_server   : not installed
jupyterlab       : not installed
nbclient         : 0.6.4
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.11
qtconsole        : not installed
traitlets        : 5.2.2
$ pip freeze | grep matplotlib
japanize-matplotlib==1.1.3
matplotlib==3.5.2
matplotlib-inline==0.1.3

内容

HTMLを使う(参考文献の方法その1)

from IPython.display import HTML
HTML(anim.to_html5_video())

rcを使う(参考文献の方法その2)

from matplotlib import rc

# equivalent to rcParams['animation.html'] = 'html5'
rc('animation', html='html5')

私としては、

import matplotlib as mpl
mpl.rcParams['animation.html'] = 'html5'

だが、与えられた書き方の方が簡潔かもしれない。

%matplotlib notebookを使ってしまう(我流)

%matplotlib notebook

一時的にinlineを諦めるやり方だが、HTMLを使うと何故か私の環境ではかなり重いので、こちらもあり。
ただし、図右上の電源ボタンを押さないと、後のplotが混ざる。

感想

使いこなしてスタイリッシュにビジュアライゼーションしたい。。

参考文献

0
0
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
0
0