繁体   English   中英

Python:如何使用大型数据集创建 3D 散点图 plot 并为每个点分配不透明度/透明度?

[英]Python: How to create a 3D scatter plot and assign an opacity/transparency to each point, with a large dataset?

所以我正在处理一些 3D 雷达数据,它基本上由一个 3D 值数组组成,这些值对应于返回功率,这是由一些 object 的反射引起的。

因为它是 3D 卷,所以很难在图形/图像等中正确显示。例如,您想要查看的数据被外部数据隐藏。

我想做的是创建一个 3D 散点图 plot 这个数据,其中每个点的不透明度由相应的 xyz(像素)位置的值定义。

我使用过 matplotlibs scatter plot 但不幸的是使用起来很慢,而且我对其他绘图工具的了解非常有限。 Using matplotlib above 1000 points makes it really slow to manipulate the 3D plot so I'm looking for another plotting tool, pyqtgraph, mayavi etc. But it doesn't seem easy to build the scatter plot by the individual xyz points with other tools.

这是我使用的代码,使用随机 3D 数组代替我的数据(我使用的数据大小相同),它的值在 0 和 1 之间,因此无需标准化等。

points = np.random.rand(100,20,20)

def Scatter_Plot(points):
    fig = plt.figure()
    ax = fig.add_subplot(projection='3d')

    for x in range(0,points.shape[0]):
        for y in range(0,points.shape[1]):
            for z in range(0,points.shape[2]):
                val = points[x,y,z]
                ax.scatter(x, y, z, alpha=val,c='black',s=3)
    plt.show()

谢谢您的帮助

这是你想要的吗?

import numpy as np
from matplotlib import pyplot as plt

points = np.random.rand(100, 20, 20)


def Scatter_Plot(points):
    fig = plt.figure()
    ax = fig.add_subplot(projection='3d')
    from itertools import product

    x, y, z = zip(*list(product(*map(range, points.shape))))
    val = points.flatten()

    ax.scatter(x, y, z, alpha=val, c='black', s=3)
    plt.show()


Scatter_Plot(points)

在此处输入图像描述

使用您的代码,最好为它们创建列表值和 append,而不是每次通过 for 循环尝试绘制 go 的图形(这是永远的事情)。 如果您使用大于 3.4 的 Matplotlib 版本,您甚至可以使用 arrays 作为色调值。*:

points = np.random.rand(100,20,20)

def Scatter_Plot(points):
    fig = plt.figure()
    ax = fig.add_subplot(projection='3d')

    xList = []
    yList = []
    zList = []
    valList = []
    for x in range(0,points.shape[0]):
        for y in range(0,points.shape[1]):
            for z in range(0,points.shape[2]):
                xList.append(x)
                yList.append(y)
                zList.append(z)
                valList.append(points[x,y,z])

    ax.scatter(xList, yList, zList, alpha=np.array(valList), c='black',s=3)

    plt.show()
Scatter_Plot(points)

Output:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM