【问题标题】:How to blur points in 3d matplotlib [closed]如何模糊 3d matplotlib 中的点 [关闭]
【发布时间】:2013-08-22 21:44:23
【问题描述】:

是否可以根据距视点的距离来模糊 matplotlib 3d 中的某些数据点。我知道它只会使这些点变得不透明。

我正在寻找类似的东西;

http://vimeo.com/15669684

【问题讨论】:

    标签: python animation matplotlib plot blurry


    【解决方案1】:

    您可以使用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)
    

    【讨论】:

    • 需要什么版本的matplotlib?因为当使用 mpl 版本 1.1.1rc (ubuntu 12.04) 在本地运行代码时,它似乎只会改变点的不透明度。
    • 它们也应该随机晃动一点...我使用的是matplotlib 1.3.0...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多