Published
Edited
Mar 18, 2021
1 fork
18 stars
Insert cell
Insert cell
Insert cell
Insert cell
function randomPointOnSphere() {
var theta = 6.283185 * Math.random();
var u = 2.0 * Math.random() - 1.0;
var v = Math.sqrt(1 - u * u);
return [v * Math.cos(theta), v * Math.sin(theta), u];
}
Insert cell
Insert cell
Insert cell
Insert cell
{
var div = document.createElement('div');
var x = [];
var y = [];
var z = [];
for (var i = 0; i < n; i++) {
var pt = randomPointOnSphere();
x[i] = pt[0];
y[i] = pt[1];
z[i] = pt[2];
}
Plotly.plot(
div,
[
{
type: 'scatter3d',
mode: 'markers',
marker: { size: 1 },
opacity: 10000 / n,
x,
y,
z
}
],
{
width,
height: Math.min(width, 600),
margin: { t: 0, r: 0, b: 0, l: 0 }
}
);
return div;
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more