Below is a minimal, self-contained example that you can paste into a Jupyter / IPython notebook to
• draw a 3-D point cloud with Matplotlib
• add two sliders (elevation & azimuth) so you can rotate the view
It only uses the standard Matplotlib tool-kit, plus ipywidgets, which is shipped with Jupyter Lab/Notebook by default.
# -----------------------------------------------------------
# 1. Imports & notebook backend
# -----------------------------------------------------------
%matplotlib widget # <-- IMPORTANT: activates the interactive JS backend
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D # just to register the 3D projection
import ipywidgets as widgets
# -----------------------------------------------------------
# 2. Dummy point cloud (replace by your own data)
# -----------------------------------------------------------
n = 3_000
pts = np.random.normal(size=(n, 3)) # [N,3] array
# -----------------------------------------------------------
# 3. Create the figure & scatter plot
# -----------------------------------------------------------
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111, projection='3d')
sc = ax.scatter(pts[:, 0], pts[:, 1], pts[:, 2],
s=5, c=pts[:, 2], cmap='viridis', alpha=.8)
ax.set_xlabel('X'); ax.set_ylabel('Y'); ax.set_zlabel('Z')
ax.set_box_aspect([1, 1, 1]) # equal aspect for x/y/z
# -----------------------------------------------------------
# 4. Widget-driven rotation
# -----------------------------------------------------------
def rotate(elev=30, azim=30):
"""Update the camera view and redraw."""
ax.view_init(elev, azim)
fig.canvas.draw_idle() # lightweight redraw, no flicker
elev_slider = widgets.IntSlider(
value=30, min=-90, max=90, step=5,
description='Elevation', continuous_update=False)
azim_slider = widgets.IntSlider(
value=30, min=-180, max=180, step=5,
description='Azimuth', continuous_update=False)
ui = widgets.HBox([elev_slider, azim_slider])
out = widgets.interactive_output(rotate, {'elev': elev_slider,
'azim': azim_slider})
display(ui, out)
What you get
• A fully interactive matplotlib canvas (thanks to %matplotlib widget) – you can still drag with the mouse/trackpad if you want.
• Two sliders underneath. Dragging them changes the camera elevation (up/down) and azimuth (left/right) in real time.
Customization tips
-
Point size / color
Change the s=, c=, and cmap= arguments in ax.scatter.
-
Automatic rotation / animation
You can attach a widgets.Play to the azimuth slider for a turn-table effect:
play = widgets.Play(value=0, min=0, max=360, step=2, interval=50) # 20 fps
widgets.jslink((play, 'value'), (azim_slider, 'value'))
display(play)
-
Large point clouds
For > ~1e5 points, consider ax.voxels, Mayavi, or pythreejs for GPU performance.
But up to about 100k points Matplotlib + WebGL backend remains usable.
-
No widgets?
If you don’t install ipywidgets, simply using %matplotlib widget already gives mouse-interactive rotation; the sliders are just a nice extra.
That’s it—have fun spinning your cloud! 🌀