python-3.x - 使用 matplotlib 将 3D 散点图动画化为 gif 最终为空

标签 python-3.x animation matplotlib gif scatter

所以这是我的代码:

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='.'

关于python-3.x - 使用 matplotlib 将 3D 散点图动画化为 gif 最终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51457738/

相关文章:

python-3.x - 如何使用 Pandas groupby() 将列的逗号分隔项的字符串聚合到列表中?

python - 在python中通过json递归

iphone - 如何在iphone中制作烟雾效果?

iphone - 在 iOS 上使用动画从右到左调整 View 大小

python - 安装 "scientific python"环境: OS X 10. 7 + Numpy + Scipy + Matplotlib

python - 列表中的 Tkinter Entry 小部件都保存相同的数据

if else 语句上的 python 3.5.1 语法错误

快速动画 - 触地得分效果不佳

python - Matplotlib FuncAnimation 逐步动画函数

python - 在同一图表中绘制 pandas 中的两个数字列,日期在 x 轴上