import json
import plotly.plotly as py
import plotly.graph_objs as go
import math
from plotly import tools
import copy
#data related to the ring cyclide is loaded
with open('2381.json') as data_file:
fig = json.load(data_file)
data_original = fig['data'][0] #this will be 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)
print(len(out))
print(len(out[0]))
data['surfacecolor'] = out #sets surface-color to distance from the origin
300 300
print(data.keys())
print(data_original.keys())
[u'name', u'colorscale', 'surfacecolor', u'y', u'x', u'z', u'type'] [u'name', u'colorscale', u'y', u'x', u'z', u'type']
## This section deals with the layout of the plot
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], 3.5]
)
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=9000)
fig['layout']['scene1'].update(scene)
fig['layout']['scene2'].update(scene)
fig['layout']['annotations'] = [
dict(
x=0.1859205,
y=0.95, #0.9395833,
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
)
]
plot_url = py.plot(fig, filename='multiple_surface_plots', auto_open=False)
This is the format of your plot grid: [ (1,1) scene1 ] [ (1,2) scene2 ]
tools.embed('https://plotly.com/~kevintest/333/ring-cyclide/')
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 publisher --upgrade
import publisher
publisher.publish(
'surface-subplots.ipynb', 'python/demo/surface-subplots//', 'Surface Subplot Demo',
'Surface Subplot Demo',
title = 'Surface Subplot Demo',
thumbnail='', language='python',
layout='user-guide', has_thumbnail='false')
Requirement already up-to-date: publisher in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you "Save" this notebook before running this command? Remember to save, always save. warnings.warn('Did you "Save" this notebook before running this command? ' /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:58: UserWarning: Your URL has more than 2 parts... are you sure? warnings.warn('Your URL has more than 2 parts... are you sure?')