## Subplots 3D¶

In [1]:
import scipy.integrate as integrate
import numpy as np


Subplot 1, Chua's attractor

In [2]:
def Chua((x, y, z), t0, k=1, alpha=15.6,  beta=28,  gamma=0, m0=-1.143, m1=-0.714):
h=lambda x: m1*x+0.5*(m0-m1)*(abs(x+1)-abs(x-1))

return [k*alpha*(y-x-h(x)),  k*(x - y+ z), -k*(beta*y+gamma*z)]


Integrate Chua's system of differential equations defined by the function Chua:

In [3]:
x0=[0.7, 0,0]
t = np.linspace(0, 100, 2000)
xt = integrate.odeint(Chua, x0, t)# xt is the solution x(t) as a numpy arrayof shape (2000,  3)


Subplot 2, Hamiltonian surface $z=H(x,y)$:

In [4]:
H=lambda x,y: 0.5*y**2+x**3/3.0-x


Surface discretization:

In [5]:
x2=np.arange(-2, 2, 0.1)
y2=np.arange(-2, 2, 0.1)
X2,Y2=np.meshgrid(x2,y2)
z2=H(X2,Y2)


Subplot 3, Mount Bruno:

In [6]:
dem6cs=[[0.0, '#32924c'],  # custom colorscale
[0.1, '#52a157'],
[0.2, '#74b162'],
[0.3, '#94c06d'],
[0.4, '#b6d079'],
[0.5, '#d7de84'],
[0.6, '#c9c370'],
[0.7, '#bba65b'],
[0.9, '#9f6d32'],
[1.0, '#91511e']]

In [7]:
#Data source: https://plot.ly/~mariahh/143/


Subplot 4, Dini surface:

In [8]:
u=np.linspace(0, 4*np.pi, 300)
v=np.linspace(0.1, 1.2, 100)
u,v=np.meshgrid(u,v)
x4=np.cos(u)*np.sin(v)
y4=np.sin(u)*np.sin(v)
z4=np.cos(v)+np.log(np.tan(v/2))+0.2*u

In [12]:
import plotly.plotly as py
from plotly.graph_objs import *
from plotly import tools
py.sign_in('empet', 'my_api_key')

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

This is the format of your plot grid:
[ (1,1) scene1 ]  [ (1,2) scene2 ]
[ (2,1) scene3 ]  [ (2,2) scene4 ]



Having comma after z4, x4 and y4 they are interpreted as tuples of shape (1,). That is why we take in the trace definition x4[0], etc.

In [14]:
fig.append_trace(dict(type='scatter3d', x=xt[:,0], y=xt[:,1], z=xt[:,2], mode='lines',
scene='scene1', showlegen=False), 1, 1)
fig.append_trace(dict(type='surface', x=x2, y=y2, z=z2, colorscale='Viridis',
scene='scene2', showscale=False), 1, 2)
fig.append_trace(dict(type='surface',  z=z3, colorscale=dem6cs,
scene='scene3', showscale=False), 2, 1)
fig.append_trace(dict(type='surface', x=x4, y=y4, z=z4, colorscale='Greens',
scene='scene4', showscale=False), 2, 2)

fig['layout'].update(title="Subplots 3D.<br> 1. Chua's attractor, 2. Hamiltonian (surface)"+\
"3. Mount Bruno, 4. Dini Surface",
height=800, width=800, showlegend=False)

axis = dict(
showbackground=True,
backgroundcolor="rgb(230, 230,230)",
gridcolor="rgb(255, 255, 255)",
zerolinecolor="rgb(255, 255, 255)",
)

scene=Scene(
xaxis=XAxis(axis),
yaxis=YAxis(axis),
zaxis=ZAxis(axis)
)
fig['layout']['scene1'].update(scene)
fig['layout']['scene2'].update(scene)
fig['layout']['scene3'].update(scene)
fig['layout']['scene4'].update(scene)

py.iplot(fig, filename='Subplots-3D', validate=False)

Out[14]:
In [15]:
from IPython.core.display import HTML
def  css_styling():