在Matplotlib中动画化3D散点图序列

时间:2015-09-08 01:13:07

标签: animation matplotlib correlation data-virtualization scatter3d

我有3D时间序列数据:

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

#  make data
xs, ys, zs = np.random.normal(0, 10, 1000), np.random.normal(0, 10, 1000), np.random.normal(0, 10, 1000)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('3D acceleration vector distribution')

#  make color change over time
cm = plt.get_cmap('Set2')
colors = np.linspace(0, 1, len(xs))
my_colors = cm(colors)

ax.scatter(0, 0, 0, 'o', c='r')  # mark origin
ax.scatter(xs, ys, zs, 'o', alpha=1, c=colors, edgecolors='None',
            cmap=cm)

Scatterplot of vector data with color changing as the plot marches along the index.

如何为一次出现的点设置动画?我找到this answer但不了解如何修改更新程序功能,以便新点不会消除旧点。

奖励:如果旧点随着时间的推移逐渐消失,那么音量就不会变得杂乱。

0 个答案:

没有答案