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
      [ 269.1308613 -6.88299381 -114.09653175], [237.41664038 -26.2982995 -86.02735598], ..., [ 60.76310769 -72.68302422 -9.61229159], [ 27.98146596 -42.21381325 27.95863624]
      Values:
      array([[ 269.1308613 , -6.88299381, -114.09653175], [ 237.41664038, -26.2982995 , -86.02735598], [ 241.40159959, -14.06446819, -81.51657581], ..., [ 34.18580594, -45.9429662 , -3.17489799], [ 60.76310769, -72.68302422, -9.61229159], [ 27.98146596, -42.21381325, 27.95863624]], shape=(100000, 3))
    • (row)
      float64
      K
      37.565, 30.863, ..., 139.023, 124.781
      Values:
      array([ 37.56504452, 30.86317454, 30.31648549, ..., 118.70076253, 139.02301646, 124.78085357], shape=(100000,))

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

[3]:
pp.scatter3d(da, pos='position', color='black', size=2)
[3]:

Scatter plot with colorbar#

To make a scatter plot with a colorbar mapping data values to colors, use cbar=True.

[4]:
pp.scatter3d(da, pos='position', cbar=True, size=2)
[4]:

Scatter plot using individual coordinates#

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

[5]:
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', size=0.2, cbar=True)
[5]: