Show Sidebar Hide Sidebar

3D Subplots in Python

3D Subplots in Plotly

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

In [1]:
import plotly 
plotly.__version__
Out[1]:
'2.0.7'

3D Surface Subplots

In [2]:
import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools

import numpy as np

x = np.linspace(-5, 80, 10)
y = np.linspace(-5, 60, 10)
xGrid, yGrid = np.meshgrid(y, x)
z = xGrid ** 3 + yGrid ** 3

scene = dict(
    xaxis=dict(
        gridcolor='rgb(255, 255, 255)',
        zerolinecolor='rgb(255, 255, 255)',
        showbackground=True,
        backgroundcolor='rgb(230, 230,230)'
    ),
    yaxis=dict(
        gridcolor='rgb(255, 255, 255)',
        zerolinecolor='rgb(255, 255, 255)',
        showbackground=True,
        backgroundcolor='rgb(230, 230,230)'
    ),
    zaxis=dict(
        gridcolor='rgb(255, 255, 255)',
        zerolinecolor='rgb(255, 255, 255)',
        showbackground=True,
        backgroundcolor='rgb(230, 230,230)'
    )
)

fig = tools.make_subplots(rows=2, cols=2,
                          specs=[[{'is_3d': True}, {'is_3d': True}],
                                 [{'is_3d': True}, {'is_3d': True}]])

# adding surfaces to subplots.
fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='Viridis',
                      scene='scene1', showscale=False), 1, 1)
fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='RdBu',
                      scene='scene2', showscale=False), 1, 2)
fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='YIOrRd',
                      scene='scene3', showscale=False), 2, 1)
fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='YIGnBu',
                      scene='scene4', showscale=False), 2, 2)

fig['layout'].update(title='subplots with different colorscales',
                     height=800, width=800)
fig['layout']['scene1'].update(scene)
fig['layout']['scene2'].update(scene)
fig['layout']['scene3'].update(scene)
fig['layout']['scene4'].update(scene)

py.iplot(fig, file_name='multiple_plots')
This is the format of your plot grid:
[ (1,1) scene1 ]  [ (1,2) scene2 ]
[ (2,1) scene3 ]  [ (2,2) scene4 ]

Out[2]:

Reference

See https://plot.ly/python/subplots/ for more information regarding subplots!

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.