2013-08-22 29 views

回答

0

您可以用模糊的色彩映射的一个从matplotlib.cm

在下面的玩具示例中,它对z坐标进行线性插值,该坐标定义每个标记的颜色。通过zbfzbb给出在前景和背景上指示z值的限制。

import matplotlib.pyplot as plt 
from matplotlib.animation import FuncAnimation 
import matplotlib.cm as cm 
import numpy as np 

n = 10 
frames = 100 
x = np.random.random(n) 
y = np.random.random(n) 
z = np.random.random(n) 

zbb = 0. # z_blur_back 
zbf = 1. # z_blur_fore 

ax = plt.subplot(111) 
fig = plt.gcf() 

def animate(i): 
    global x, y, z 
    x += 0.01*(-0.5 + np.random.random(n)) 
    y += 0.01*(-0.5 + np.random.random(n)) 
    z += 0.05*(-0.5 + np.random.random(n)) 

    cmnum = (z-zbf)/(zbb-zbf) 
    colors = cm.gray(cmnum) # use hot, ocean, rainbow etc... 

    fig = plt.gcf() 
    fig.clear() 
    ax = plt.gca() 
    ax.scatter(x, y, marker='o', s=200., color=colors) 
    ax.set_xlim(-0.1,1.1) 
    ax.set_ylim(-0.1,1.1) 

ani = FuncAnimation(fig, animate, frames=xrange(frames)) 
ani.save('test.mp4', fps=20) 
+0

什么版本的matplotlib是必需的?因为当使用mpl version 1.1.1rc(ubuntu 12.04)在本地运行代码时,它似乎只能改变点的不透明度。 –

+0

他们也应该随机摇一点点......我正在使用matplotlib 1.3.0 ... –