使用matplotlib将3D散点图动画为gif最终为空

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用matplotlib将3D散点图动画为gif最终为空相关的知识,希望对你有一定的参考价值。

所以这是我的代码:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation


raw = np.random.rand(100,3)
fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')
x = raw[:, 0]
y = raw[:, 1]
z = raw[:, 2]

ax.scatter(x, y, -z, zdir='z', c='black', depthshade=False, s=0.2, marker=',')

def rotate(angle):
    ax.view_init(azim=angle)

print("Making animation")
rot_animation = animation.FuncAnimation(fig, rotate, frames=np.arange(0, 362, 2), interval=100)
rot_animation.save('rotation.gif', dpi=80, writer='imagemagick')

不幸的是,得到的gif没有显示点,只是旋转轴..这是由此产生的gif:https://giphy.com/gifs/eeVv2oifDNhRYN9xMi

谢谢大家!

答案

问题有点,您希望在图表上看到什么。目前你创建0.2点大像素,所以像素小于一个像素。

也许你想用

s=1, marker='.'

以上是关于使用matplotlib将3D散点图动画为gif最终为空的主要内容,如果未能解决你的问题,请参考以下文章

3D散点图动画

如何将标签注释到 3D matplotlib 散点图?

带有颜色渐变的 Matplotlib 3D 散点图

如何在 matplotlib 中制作 3D 散点图

使用 matplotlib 保存散点图动画

在 matplotlib 中为旋转的 3D 图形制作动画