3d surface plots with IPython notebook and Plotly

3d graphs can be a mind-bender. This IPython notebook walks you through theĀ basics of building a 3d surface plot with Plotly.

The key step is creating a Plotly Surface object with x, y, and z variables:

(This surface also has a custom colors variable called “cls” – see the IPython notebook for more).

x and y are vectors or arrays of length m and n. z is a matrix of size m x n.

For example, if

then z would have to be a matrix of size 3 by 4:

And the surface plot of z would be 12 points total (3 x 4). The surface plot in this IPython notebook is much larger – 10,000 points total.

Surface objects in Plotly are added to Scene objects, which define the axes, margin, and color layout of the 3d plot. Multiple scenes can be added to a Plotly figure object to create 3d subplots, like this one created in MATLAB:


Here is the interactive 3d plot created in this IPython notebook:

Creating dashboards or visualizations at your company? Consider Plotly Enterprise for modern intracompany graph and data sharing.