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

问题描述

我使用 Jupyter Notebook 分析数据集.笔记本里有很多情节,其中一些是3d情节.

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.

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

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

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

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

我的想法:

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

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

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

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).

bokeh 画廊中没有找到任何实际的 3d 绘图示例.我只找到了 https://demo.bokeh.org/surface3d,它使用了 visjs代码>.

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

既然我需要的只是line and surce,是否可以在浏览器中使用js将数据传递给js plot以使其具有交互性?(然后我们可能还需要添加 3d 轴.)这可能类似于 visjsmpld3.

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.

推荐答案

尝试:

%matplotlib notebook

jakevdp 回复这里

为 JupyterLab 用户

按照说明安装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()

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

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

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

09-01 22:50