相关疑难解决方法(0)

在iPython或iPython Notebook中显示可旋转的3D图

(Mac OSX 10.10.5)

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

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

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

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

作为ipython笔记本中的一个例子:

    # 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. …
Run Code Online (Sandbox Code Playgroud)

macos plot matplotlib ipython jupyter-notebook

53
推荐指数
2
解决办法
3万
查看次数

Matplotlib 3D散射动画

我正在绘制星团中的位置,我的数据位于具有x,y,z位置的数据帧以及时间索引中.

我能够制作一个三维散点图,并试图产生一个旋转图 - 我有点成功,但在动画API中苦苦挣扎.

如果我的"update_graph"函数只返回一个新的ax.scatter(),那么旧的一个会保留绘制,除非我重建整个图形.这似乎效率低下.同样,我必须设置我的间隔相当高或我的动画"跳过"每隔一帧,所以它说我的表现相当糟糕.最后我被迫使用"blit = False",因为我无法获得3d散点图的迭代器.显然"graph.set_data()"不起作用,我可以使用"graph.set_3d_properties"但只允许我使用新的z坐标.

所以我拼凑了一个cluuge--(我使用的数据是 https://www.kaggle.com/mariopasquato/star-cluster-simulations 滚动到底部)

另外我只绘制100个点(data = data [data.id <100])

我的(工作)代码如下:

def update_graph(num):
     ax = p3.Axes3D(fig)
     ax.set_xlim3d([-5.0, 5.0])
     ax.set_xlabel('X')
     ax.set_ylim3d([-5.0, 5.0])
     ax.set_ylabel('Y')
     ax.set_zlim3d([-5.0, 5.0])
     ax.set_zlabel('Z')
     title='3D Test, Time='+str(num*100)
     ax.set_title(title)
     sample=data0[data0['time']==num*100]
     x=sample.x
     y=sample.y
     z=sample.z
     graph=ax.scatter(x,y,z)
     return(graph)

fig = plt.figure()
ax = p3.Axes3D(fig)

# Setting the axes properties
ax.set_xlim3d([-5.0, 5.0])
ax.set_xlabel('X')
ax.set_ylim3d([-5.0, 5.0])
ax.set_ylabel('Y')
ax.set_zlim3d([-5.0, 5.0])
ax.set_zlabel('Z')
ax.set_title('3D Test')
data=data0[data0['time']==0]
x=data.x
y=data.y
z=data.z
graph=ax.scatter(x,y,z)

# Creating the Animation object
line_ani = animation.FuncAnimation(fig, update_graph, 19, 
                               interval=350, blit=False)
plt.show()
Run Code Online (Sandbox Code Playgroud)

python 3d plot animation matplotlib

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

matplotlib ×2

plot ×2

3d ×1

animation ×1

ipython ×1

jupyter-notebook ×1

macos ×1

python ×1