【发布时间】:2013-08-22 21:44:23
【问题描述】:
【问题讨论】:
标签: python animation matplotlib plot blurry
【问题讨论】:
标签: python animation matplotlib plot blurry
您可以使用matplotlib.cm 中的一种颜色图进行模糊处理。
在下面的玩具示例中,它对定义每个标记的颜色的z 坐标进行了线性插值。由zbf 和zbb 给出了在前景和背景上告诉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)
【讨论】: