Scatter3d plot#

The scatter3d plot creates a three-dimensional scatter plot of the data.

[1]:
import plopp as pp
import scipp as sc
import numpy as np

Scatter plot using a positions vector#

The easiest way to generate a scatter plot is to use a coordinate of the data array that contains data of the vector3 dtype.

We first generate some fake data, meant to represent clusters of points in a three-dimensional space.

[2]:
nclusters = 100
npercluster = 1000

position = np.zeros((nclusters, npercluster, 3))
values = np.zeros((nclusters, npercluster))

for n in range(nclusters):
    center = 500.0 * (np.random.random(3) - 0.5)
    r = 20.0 * np.random.normal(size=[npercluster, 3])
    position[n, :] = r + center
    values[n, :] = np.linalg.norm(r, axis=1) + n

da = sc.DataArray(
    data=sc.array(dims=['row'], values=values.flatten(), unit='K'),
    coords={
        'position': sc.vectors(
            dims=['row'], unit='m', values=position.reshape(nclusters * npercluster, 3)
        )
    },
)
da
[2]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (3.05 MB)
    • row: 100000
    • position
      (row)
      vector3
      m
      [-76.13129326 -88.37073708 5.8098165 ], [-66.68692932 -56.20108856 -20.42663108], ..., [168.56309188 266.23286932 2.89366308], [186.60409709 236.88744043 17.74111843]
      Values:
      array([[-76.13129326, -88.37073708, 5.8098165 ], [-66.68692932, -56.20108856, -20.42663108], [-77.67701752, -51.13097608, -3.29481731], ..., [189.82706032, 232.78496129, 19.01737188], [168.56309188, 266.23286932, 2.89366308], [186.60409709, 236.88744043, 17.74111843]])
    • (row)
      float64
      K
      18.043, 28.894, ..., 122.268, 117.218
      Values:
      array([ 18.04264072, 28.89390404, 20.37370672, ..., 122.39614079, 122.26778388, 117.21838852])

We then simply specify the name of the coordinate that contains the vector positions using the pos argument:

[3]:
pp.scatter3d(da, pos='position')
[3]:

Scatter plot using individual coordinates#

It is also possible to create scatter plots using three individual coordinate names for the x, y, z dimensions:

[4]:
time = np.linspace(0, 10, 50)
x = np.cos(time)
y = np.sin(time)

da = sc.DataArray(
    data=sc.array(dims=['row'], values=time),
    coords={
        'x': sc.array(dims=['row'], unit='m', values=x),
        'y': sc.array(dims=['row'], unit='m', values=y),
        'time': sc.array(dims=['row'], unit='s', values=time),
    },
)

pp.scatter3d(da, x='x', y='y', z='time', pixel_size=0.2)
[4]: