<jupyter_start><jupyter_text>New to Plotly?Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).You can set up Plotly to work in [online](https://plot.ly/python/getting-started/initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/start-plotting-online).We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! Version CheckPlotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version.<jupyter_code>import plotly
plotly.__version__<jupyter_output><empty_output><jupyter_text>Color by VariableBy default, surface plots are colored by the `z` variable. Now, users have the option of setting the attribute `surfacecolor` to a variable to color by an independed variable.<jupyter_code>import plotly.plotly as py
from plotly import tools

import copy
import json
import math
import urllib2

# load ring cyclide data
response = urllib2.urlopen('https://plot.ly/~empet/2381.json')
data_file = response.read()
fig = json.loads(data_file)

data_original = fig['data'][0]        # trace0
data = copy.deepcopy(fig['data'])[0]  # trace1

lx = len(data['z'])
ly = len(data['z'][0])
out = []

def dist_origin(x, y, z):
    return math.sqrt((1.0 * x)**2 + (1.0 * y)**2 + (1.0 * z)**2)

for i in xrange(lx):
    temp = []
    for j in xrange(ly):
        temp.append(
            dist_origin(data['x'][i][j], data['y'][i][j], data['z'][i][j]))
    out.append(temp)

data['surfacecolor'] = out     # sets surface-color to distance from the origin

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)'
    ),
    cameraposition=[[0.2, 0.5, 0.5, 0.2], [0, 0, 0], 4.8]
)

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

# adding surfaces to subplots.
data_original['scene'] = 'scene1'
data_original['colorbar'] = dict(x=-0.07)

data['scene'] = 'scene2'
fig.append_trace(data_original, 1, 1)
fig.append_trace(data, 1, 2)

fig['layout'].update(title='Ring Cyclide',
                     height=800, width=950)
fig['layout']['scene1'].update(scene)
fig['layout']['scene2'].update(scene)
fig['layout']['annotations'] = [
    dict(x=0.1859205, y=0.95,     
         xref='x', yref='y',
         text='4th Dim Prop. to z',
         showarrow=False),
    dict(x=0.858, y=0.95,
         xref='x', yref='y',
         text='4th Dim Prop. to Distance from Origin',
         showarrow=False)
]

py.iplot(fig, filename='surface-coloring')<jupyter_output>This is the format of your plot grid:
[ (1,1) scene1 ]  [ (1,2) scene2 ]<jupyter_text>Reference See https://plot.ly/python/reference/surface-surfacecolor for more information!<jupyter_code>from IPython.display import display, HTML

display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))

! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
    
publisher.publish(
    '3d_surface_coloring.ipynb', 'python/3d-surface-coloring/', '3D Python Surface Coloring | plotly',
    'How to Color 3D Surface Plots in Python with Plotly.',
    title = '3D Surface Coloring in Python | plotly',
    name = '3D Surface Coloring',
    has_thumbnail='true', thumbnail='thumbnail/3d-surface-color.jpg', 
    language='python',
    display_as='style_opt', order=7,
    ipynb= '~notebook_demo/76')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1592255125284738, 'fraction_numerical': 0.04305239179954442, 'mean_word_length': 4.093967517401392, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '217602', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1485, 'n_words': 330, 'path': '_posts/python-v3/3d/3d-surface-coloring/3d_surface_coloring.ipynb', 'repo_name': 'bmb804/documentation', 'size': '4390'}