簡體   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