python& Matplotlib:在Jupyter Notebook中使3D绘图具有交互性 [英] Python & Matplotlib: Make 3D plot interactive in Jupyter Notebook

查看:367
本文介绍了python& Matplotlib:在Jupyter Notebook中使3D绘图具有交互性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Jupyter Notebook对数据集进行分析.笔记本中有很多图,其中一些是3d图.

我想知道是否可以使3d绘图具有交互性,以便以后可以更详细地使用它吗?

也许我们可以在上面添加一个按钮?点击它可以弹出3D图,人们可以缩放,平移,旋转等.


我的思想:

1. matplotlib,%qt

这不适合我的情况,因为我需要在3d绘图后继续绘图. %qt将干扰以后的绘图.

2. mpld3

在我的情况下,

mpld3几乎是理想的,不需要重写任何内容,与matplotlib兼容.但是,它仅支持2D图.而且我没有看到任何针对3D的计划( https://github.com/mpld3/mpld3 /issues/223 ).

3.散景+ visjs

bokeh图库中找不到任何3d绘图的实际示例.我只找到使用visjs https://demo.bokeh.org/surface3d .

4. Javascript 3D图?

由于我所需要的只是线条和背景,是否有可能在浏览器中使用js将数据传递到js绘图以使其具有交互性? (然后,我们可能还需要添加3d轴.)这可能类似于visjsmpld3.

解决方案

尝试:

%matplotlib notebook

请参见 jakevdp 回复 此处

为JupyterLab用户

按照说明安装. com/matplotlib/jupyter-matplotlib"rel =" noreferrer> jupyter-matplotlib

然后不再需要上面的魔术命令,如示例所示:

# Enabling the `widget` backend.
# This requires jupyter-matplotlib a.k.a. ipympl.
# ipympl can be install via pip or conda.
%matplotlib widget
# aka import ipympl

import matplotlib.pyplot as plt

plt.plot([0, 1, 2, 2])
plt.show()

最后,请注意Maarten Breddels的回复;恕我直言 ipyvolume 确实非常令人印象深刻(而且非常有用!).

I use Jupyter Notebook to make analysis of datasets. There are a lot of plots in the notebook, and some of them are 3d plots.

I'm wondering if it is possible to make the 3d plot interactive, so I can later play with it in more details?

Maybe we can add a button on it? Clicking it can pop out a 3d plot and people can zoom, pan, rotate etc.


My thougths:

1. matplotlib, %qt

This does not fit my case, because I need to continue plot after the 3d plot. %qt will interfere with later plots.

2. mpld3

mpld3 is almost ideal in my case, no need to rewrite anything, compatible with matplotlib. However, it only support 2D plot. And I didn't see any plan working on 3D (https://github.com/mpld3/mpld3/issues/223).

3. bokeh + visjs

Didn't find any actualy example of 3d plot in bokeh gallery. I only find https://demo.bokeh.org/surface3d, which uses visjs.

4. Javascript 3D plot?

Since what I need is just line and surce, is it possible to pass the data to js plot using js in the browser to make it interacive? (Then we may need to add 3d axis as well.) This may be similar to visjs, and mpld3.

解决方案

try:

%matplotlib notebook

see jakevdp reply here

EDIT for JupyterLab users:

Follow the instructions to install jupyter-matplotlib

Then the magic command above is no longer needed, as in the example:

# Enabling the `widget` backend.
# This requires jupyter-matplotlib a.k.a. ipympl.
# ipympl can be install via pip or conda.
%matplotlib widget
# aka import ipympl

import matplotlib.pyplot as plt

plt.plot([0, 1, 2, 2])
plt.show()

Finally, note Maarten Breddels' reply; IMHO ipyvolume is indeed very impressive (and useful!).

这篇关于python& Matplotlib:在Jupyter Notebook中使3D绘图具有交互性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆