3-D scatter plot with threshold#
scatter3d
may be used to visualize dense volumes of data. To make this useful, we may however need to hide data points that are zero or below a threshold. The following example demonstrates how this can be done using generic Scipp utilities.
Consider the following 3-D volume data:
[1]:
import scipp as sc
import plopp as pp
x = sc.linspace('x', 0.0, 10.0, num=40, unit='rad')
y = sc.linspace('y', 0.0, 10.0, num=40, unit='rad')
z = sc.linspace('z', 0.0, 10.0, num=40, unit='rad')
da = sc.DataArray(sc.sin(x) * sc.sin(y) * sc.sin(z), coords={'x': x, 'y': y, 'z': z})
da
[1]:
scipp.DataArray (502.44 KB)
- x: 40
- y: 40
- z: 40
- x(x)float64rad0.0, 0.256, ..., 9.744, 10.0
Values:
array([ 0. , 0.25641026, 0.51282051, 0.76923077, 1.02564103, 1.28205128, 1.53846154, 1.79487179, 2.05128205, 2.30769231, 2.56410256, 2.82051282, 3.07692308, 3.33333333, 3.58974359, 3.84615385, 4.1025641 , 4.35897436, 4.61538462, 4.87179487, 5.12820513, 5.38461538, 5.64102564, 5.8974359 , 6.15384615, 6.41025641, 6.66666667, 6.92307692, 7.17948718, 7.43589744, 7.69230769, 7.94871795, 8.20512821, 8.46153846, 8.71794872, 8.97435897, 9.23076923, 9.48717949, 9.74358974, 10. ]) - y(y)float64rad0.0, 0.256, ..., 9.744, 10.0
Values:
array([ 0. , 0.25641026, 0.51282051, 0.76923077, 1.02564103, 1.28205128, 1.53846154, 1.79487179, 2.05128205, 2.30769231, 2.56410256, 2.82051282, 3.07692308, 3.33333333, 3.58974359, 3.84615385, 4.1025641 , 4.35897436, 4.61538462, 4.87179487, 5.12820513, 5.38461538, 5.64102564, 5.8974359 , 6.15384615, 6.41025641, 6.66666667, 6.92307692, 7.17948718, 7.43589744, 7.69230769, 7.94871795, 8.20512821, 8.46153846, 8.71794872, 8.97435897, 9.23076923, 9.48717949, 9.74358974, 10. ]) - z(z)float64rad0.0, 0.256, ..., 9.744, 10.0
Values:
array([ 0. , 0.25641026, 0.51282051, 0.76923077, 1.02564103, 1.28205128, 1.53846154, 1.79487179, 2.05128205, 2.30769231, 2.56410256, 2.82051282, 3.07692308, 3.33333333, 3.58974359, 3.84615385, 4.1025641 , 4.35897436, 4.61538462, 4.87179487, 5.12820513, 5.38461538, 5.64102564, 5.8974359 , 6.15384615, 6.41025641, 6.66666667, 6.92307692, 7.17948718, 7.43589744, 7.69230769, 7.94871795, 8.20512821, 8.46153846, 8.71794872, 8.97435897, 9.23076923, 9.48717949, 9.74358974, 10. ])
- (x, y, z)float64𝟙0.0, 0.0, ..., -0.093, -0.161
Values:
array([[[ 0. , 0. , 0. , ..., -0. , -0. , -0. ], [ 0. , 0. , 0. , ..., -0. , -0. , -0. ], [ 0. , 0. , 0. , ..., -0. , -0. , -0. ], ..., [-0. , -0. , -0. , ..., 0. , 0. , 0. ], [-0. , -0. , -0. , ..., 0. , 0. , 0. ], [-0. , -0. , -0. , ..., 0. , 0. , 0. ]], [[ 0. , 0. , 0. , ..., -0. , -0. , -0. ], [ 0. , 0.01631166, 0.03155675, ..., -0.00401093, -0.02015971, -0.03499032], [ 0. , 0.03155675, 0.06105011, ..., -0.0077596 , -0.03900125, -0.06769273], ..., [-0. , -0.00401093, -0.0077596 , ..., 0.00098626, 0.00495715, 0.0086039 ], [-0. , -0.02015971, -0.03900125, ..., 0.00495715, 0.02491556, 0.04324482], [-0. , -0.03499032, -0.06769273, ..., 0.0086039 , 0.04324482, 0.0750581 ]], [[ 0. , 0. , 0. , ..., -0. , -0. , -0. ], [ 0. , 0.03155675, 0.06105011, ..., -0.0077596 , -0.03900125, -0.06769273], [ 0. , 0.06105011, 0.11810835, ..., -0.01501183, -0.07545233, -0.13095924], ..., [-0. , -0.0077596 , -0.01501183, ..., 0.00190804, 0.00959016, 0.01664521], [-0. , -0.03900125, -0.07545233, ..., 0.00959016, 0.04820196, 0.08366199], [-0. , -0.06769273, -0.13095924, ..., 0.01664521, 0.08366199, 0.14520839]], ..., [[-0. , -0. , -0. , ..., 0. , 0. , 0. ], [-0. , -0.00401093, -0.0077596 , ..., 0.00098626, 0.00495715, 0.0086039 ], [-0. , -0.0077596 , -0.01501183, ..., 0.00190804, 0.00959016, 0.01664521], ..., [ 0. , 0.00098626, 0.00190804, ..., -0.00024252, -0.00121893, -0.00211564], [ 0. , 0.00495715, 0.00959016, ..., -0.00121893, -0.00612658, -0.01063362], [ 0. , 0.0086039 , 0.01664521, ..., -0.00211564, -0.01063362, -0.01845631]], [[-0. , -0. , -0. , ..., 0. , 0. , 0. ], [-0. , -0.02015971, -0.03900125, ..., 0.00495715, 0.02491556, 0.04324482], [-0. , -0.03900125, -0.07545233, ..., 0.00959016, 0.04820196, 0.08366199], ..., [ 0. , 0.00495715, 0.00959016, ..., -0.00121893, -0.00612658, -0.01063362], [ 0. , 0.02491556, 0.04820196, ..., -0.00612658, -0.03079334, -0.05344662], [ 0. , 0.04324482, 0.08366199, ..., -0.01063362, -0.05344662, -0.09276492]], [[-0. , -0. , -0. , ..., 0. , 0. , 0. ], [-0. , -0.03499032, -0.06769273, ..., 0.0086039 , 0.04324482, 0.0750581 ], [-0. , -0.06769273, -0.13095924, ..., 0.01664521, 0.08366199, 0.14520839], ..., [ 0. , 0.0086039 , 0.01664521, ..., -0.00211564, -0.01063362, -0.01845631], [ 0. , 0.04324482, 0.08366199, ..., -0.01063362, -0.05344662, -0.09276492], [ 0. , 0.0750581 , 0.14520839, ..., -0.01845631, -0.09276492, -0.16100793]]])
We can plot a slice in 2-D:
[2]:
pp.plot(da['x', 2])
[2]:
A 3-D scatter plot is not directly useful in this case:
[3]:
pp.scatter3d(da, x='x', y='y', z='z', figsize=(500, 500), size=0.15, cbar=True)
[3]:
We can use scipp.flatten and Boolean-variable indexing to apply a threshold, removing points with a value less than (in this case) 0.4
:
[4]:
tmp = da.flatten(to='voxel') # 3D -> 1D
tmp = tmp[tmp.data > sc.scalar(0.4)] # apply threshold
pp.scatter3d(tmp, x='x', y='y', z='z', figsize=(500, 500), size=0.15, cbar=True)
[4]: