jupyter notebook中使用mayavi三維繪圖庫
就像繪圖時可使把matplotlib嵌入jupyter中一樣,mayavi也在jupyter notebook中嵌入式使用。
以下假定已經安裝好了jupyter notebook和mayavi庫。
1. 安裝需要的python依賴
pip install ipywidgets ipyevents
2. 進行設置
命令行中輸入以下命令即可:
$ jupyter nbextension install --py mayavi --user
$ jupyter nbextension enable --py mayavi --user
3. 開始使用
打開jupyter notebook,在正式開始使用mayavi繪圖前,調用mayavi.mlab.init_notebook()
函數即可。
from mayavi import mlab
mlab.init_notebook()
此后,mlab繪制出來的三維圖即可內嵌於jupyter之中了。這樣嵌在jupyter中的三維圖也是可以用鼠標對其進行拖動旋轉等操作的哦~