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:

1 |
surf = Surface( x=x, y=y, z=z, colorscale=cls ) |

(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

1 2 |
x = [1,2,3] y = [1,2,3,4] |

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

1 |
z = [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ] ] |

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.