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]:
scipp.DataArray (3.05 MB)
- row: 100000
- position(row)vector3m[-156.11633804 -70.36444747 106.05716949], [-202.19248511 -39.97660904 96.31473698], ..., [ -72.65588366 119.62686072 -194.98868914], [ -59.70984041 121.42804136 -179.76002698]
Values:
array([[-156.11633804, -70.36444747, 106.05716949], [-202.19248511, -39.97660904, 96.31473698], [-102.71872044, -72.92153391, 112.12225589], ..., [ -48.96872408, 110.66874487, -223.48264512], [ -72.65588366, 119.62686072, -194.98868914], [ -59.70984041, 121.42804136, -179.76002698]], shape=(100000, 3))
- (row)float64K27.767, 81.018, ..., 132.715, 114.334
Values:
array([ 27.76704494, 81.01757462, 26.35836964, ..., 148.66028706, 132.71480132, 114.33428879], 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]: