Introduction to Data Science 7: Visualization 7.4: Interactive 3D
surface_data.csv 28 KB
Open
Downloads
Favorites
Recents
Desktop
Downloads
Documents
Name Date Modified Size
intro_slides.pdf Mar 25, 2026 3.2 MB
requirements.txt Mar 29, 2026 1 KB
surface_data.csv Mar 30, 2026 28 KB
homework_3.pdf Mar 27, 2026 890 KB
File:
No selection

Unit 7.4: Interactive 3D Visualization

Combining Data, Widgets, and Plotly

Interactive visualizations let learners explore data by manipulating parameters in real time. In this notebook we load a dataset, create an ipywidgets slider, and use it to control the amplitude of a 3D surface rendered with Plotly. The same workflow works with matplotlib, Panel, and other Python visualization libraries.

1
2
3
4
5
import numpy as np import pandas as pd import plotly.graph_objects as go from ipywidgets import interact, FloatSlider from IPython.display import display

Use the Upload File button in the toolbar to add a CSV. The file is written to the in-browser filesystem and is immediately available to pandas.

1
2
3
4
5
6
7
8
9
10
11
# Read the uploaded CSV df = pd.read_csv("surface_data.csv") print(f"Loaded {len(df):,} records, {len(df.columns)} columns") # Reshape for surface plot x = df["x"].unique() y = df["y"].unique() X, Y = np.meshgrid(x, y) Z = df["z"].values.reshape(len(y), len(x)) df.head(8)
xyz
0-6.000000-6.0000000.921994
1-5.586207-6.0000000.796034
2-5.172414-6.0000000.531627
3-4.758621-6.0000000.168203
4-4.344828-6.000000-0.237841
5-3.931035-6.000000-0.613529
6-3.517241-6.000000-0.878465
7-3.103448-6.000000-0.975218

The @interact decorator creates a widget control that re-runs the function whenever the slider moves. Drag the Amplitude slider to reshape the surface in real time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Interactive 3D surface with widget control amplitude = FloatSlider( value=1.0, min=0.2, max=3.0, step=0.1, description='Amplitude:' ) @interact(amp=amplitude) def plot_surface(amp=1.0): fig = go.Figure(data=[go.Surface( x=X, y=Y, z=Z * amp, colorscale='Plasma', showscale=True )]) fig.update_layout( title=f'Surface (amplitude={amp:.1f})', scene=dict(xaxis_title='X', yaxis_title='Y', zaxis_title='Z') ) fig.show()
1.0
0.2 3.0
Surface (amplitude=1.0)
Drag to rotate · Scroll to zoom
1.0 -1.0