import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import dim, opts
hv.extension('plotly')
Scatter3D
plots represents three-dimensional coordinates which are specified as key dimensions (kdims
, default kdims
are x, y, z). The points can be given a marker
, color
and size
. Additionally a colorbar
can be added.
Scatter3D
plots are therefore very similar to Points
and Scatter
types, but have one additional coordinate dimension.
Like other 3D elements the camera angle can be controlled using azimuth
, elevation
and distance
plot options
y,x = np.mgrid[-5:5, -5:5] * 0.1
z=np.sin(x**2+y**2)
hv.Scatter3D((x.flat,y.flat,z.flat)).opts(cmap='fire', color='z', size=5, colorbar=True, height=600, width=600)
You can also provide your data in a container and specify the kdims
to use.
data = pd.DataFrame(dict(lat=x.flat, lon=y.flat, height=z.flat))
hv.Scatter3D(data, kdims=["lat", "lon", "height"]).opts(cmap='blues', color='height', size=3, colorbar=True, height=600, width=600, colorbar_opts={'title': 'height (m)'}, marker="diamond")
Just like all regular 2D elements, Scatter3D
types can be overlaid and will follow the default color cycle:
(hv.Scatter3D(np.random.randn(100,4), vdims='Size') * hv.Scatter3D(np.random.randn(100,4)+2, vdims='Size')).opts(
opts.Scatter3D(size=(5+dim('Size'))*2, marker='diamond', height=600, width=600)
)
For full documentation and the available style and plot options, use hv.help(hv.Scatter3D).
hv.help(hv.Scatter3D)