import scipy.integrate as integrate
import numpy as np
Subplot 1, Chua's attractor
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
:
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)$:
H=lambda x,y: 0.5*y**2+x**3/3.0-x
Surface discretization:
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:
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.8, '#ad8a47'],
[0.9, '#9f6d32'],
[1.0, '#91511e']]
#Data source: https://plot.ly/~mariahh/143/
z3=np.loadtxt('Data/Mount-Bruno.txt')
Subplot 4, Dini surface:
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
import plotly.plotly as py
from plotly.graph_objs import *
from plotly import tools
py.sign_in('empet', 'my_api_key')
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.
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)
from IPython.core.display import HTML
def css_styling():
styles = open("./custom.css", "r").read()
return HTML(styles)
css_styling()