【问题标题】:Animating a 3D scatterplot with matplotlib to gif ends up empty使用 matplotlib 将 3D 散点图动画化为 gif 最终为空
【发布时间】:2018-12-29 15:54:32
【问题描述】:

这是我的代码:

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

谢谢大家!

【问题讨论】:

    标签: python-3.x animation matplotlib gif scatter


    【解决方案1】:

    问题有点,你想在图表上看到什么。目前,您创建 0.2 点大像素,因此像素小于 1 个像素。

    也许你想用

    s=1, marker='.'
    

    【讨论】:

    • 是的,做到了!谢谢!
    猜你喜欢
    • 2021-10-21
    • 2012-07-07
    • 2021-03-05
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 2013-01-22
    • 2019-03-16
    • 1970-01-01
    相关资源
    最近更新 更多