在iPython或iPython Notebook中显示可旋转的3D图 [英] Displaying rotatable 3D plots in iPython or iPython Notebook

查看:842
本文介绍了在iPython或iPython Notebook中显示可旋转的3D图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Mac OSX 10.10.5)

(Mac OSX 10.10.5)

我可以从matplotlib网站上重现 http://matplotlib.org/gallery.html#mplot3d 三维散点图的示例代码 http://matplotlib.org/examples/mplot3d/scatter3d_demo.html ,但剧情呈现为静态图像。我无法点击图表并动态旋转以查看3D绘图数据。

I can reproduce from the matplotlib website http://matplotlib.org/gallery.html#mplot3d the example code for a 3D scatter plot http://matplotlib.org/examples/mplot3d/scatter3d_demo.html, however the plot renders as a static image. I can not click on the graph and dynamically rotate to view the 3D plotted data.

我使用示例代码实现了静态3D绘图 - 在终端内使用(a)ipython,(b)终端内的ipython笔记本,以及(c)ipython从Anaconda发射器发射的笔记本。

I have achieved the static 3D plot using the example code - using (a) ipython from within Terminal, (b) ipython notebook from within terminal, and (c) ipython notebook launched from the Anaconda launcher.

我认为我错过了一些非常基本的步骤作为假设的知识。

I think I am missing some very basic step as assumed knowledge.

在过去的学习中,plotting已经打开了一个GUI Python App,它有一个图形查看器。 (下面显示的代码中的解决方案2打开了这个。)也许我需要知道将输出图导出到该显示方法的代码? (是的,使用%matplotlib(仅)作为没有内联或笔记本的第一行,如下面代码块中的注释所示。)

In past learning, plotting has opened a GUI Python App which has a graph viewer. (Solution 2 in code shown below opens this.) Perhaps I need to know the code to export the output graph to that display method? (Yes, use %matplotlib (only) as first line without inline or notebook as shown in comments in code block below.)

作为ipython笔记本中的示例:

As an example in ipython notebook:

    # These lines are comments
    # Initial setup from an online python notebook tutorial is below. 
    # Note the first line "%matplotlib inline" this is how the tutorial has it.
    # Two solutions 1. use: "%matplotlib notebook" graphs appear dynamic in the notebook.
    #               2. use: "%matplotlib" (only) graphs appear dynamic in separate window. 
    #    ( 2. is the best solution for detailed graphs/plots. )

    %matplotlib inline  
    import pandas as pd
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D

    pd.set_option('html',False)
    pd.set_option('max_columns',30)
    pd.set_option('max_rows',10)


    # What follows is a copy of the 3D plot example code.
    # Data is randomly generated so there is no external data import.

    def randrange(n, vmin, vmax):
        return (vmax-vmin)*np.random.rand(n) + vmin

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    n = 100
    for c, m, zl, zh in [('r', 'o', -60, -25), ('b', '^', -30, -5)]:
        xs = randrange(n, 23, 50)
        ys = randrange(n, 0, 100)
        zs = randrange(n, zl, zh)
        ax.scatter(xs, ys, zs, c=c, marker=m)

    ax.set_xlabel('X Label')
    ax.set_ylabel('Y Label')
    ax.set_zlabel('Z Label')

    plt.show()

有人可以识别我缺少的东西吗?

Can someone identify what I am missing?

看Python 3.3.6文档,第25.1节可能是tkinter包...

Looking at Python 3.3.6 documentation, section 25.1perhaps the tkinter package ...


tkinter包(Tk接口)是标准的Python接口到Tk GUI工具包。 Tk和tkinter都可用于大多数Unix平台以及Windows系统。

The tkinter package ("Tk interface") is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems.

我认为,这与开发相关GUI程序所以我不确定这是否相关。 (正确,这不是解决方案所必需的。)

I think though, this relates to development of GUI programs so I am not sure this is relevant. (Correct, this was not needed for the solution.)

推荐答案

使用%matplotlib notebook 而不是%matplotlib inline 来获取IPython笔记本中的嵌入式交互式数字 - 这需要最新版本的matplotlib(1.4+)和IPython(3.0 +)。

Use %matplotlib notebook instead of %matplotlib inline to get embedded interactive figures in the IPython notebook – this requires recent versions of matplotlib (1.4+) and IPython (3.0+).

这篇关于在iPython或iPython Notebook中显示可旋转的3D图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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