如何在三维matplotlib中模糊点

2024-04-24 23:36:02 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以根据距离观察点的距离模糊matplotlib 3d中的一些数据点。我知道这只会使点不透明。在

我在找类似的东西

http://vimeo.com/15669684


Tags: 数据comhttp距离matplotlibvimeo观察点使点
1条回答
网友
1楼 · 发布于 2024-04-24 23:36:02

您可以使用matplotlib.cm中的一种颜色贴图进行模糊处理。在

在下面的玩具示例中,z坐标的线性插值定义了每个标记的颜色。告诉前景和背景上z值的限制由zbf和{}给出。在

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)

相关问题 更多 >