import plotly.offline as py
from plotly.graph_objs import *
import numpy as np
from numpy import pi, cos, sin, exp, log, sqrt
py.init_notebook_mode()
def snake(u,v):
lu, lv = len(u), len(v)
path = []
i, j = 0, 0
istep, jstep = 1, 1
while(i < lu):
while(0 <= j < lv):
path.append((u[i],v[j]))
j += jstep
j -= jstep
i += istep
jstep *= -1
i -= istep
i -= istep
istep *= -1
while(0 <= j < lv):
while(0 <= i < lu):
path.append((u[i],v[j]))
i += istep
i -= istep
j += jstep
istep *= -1
return path
def surface(rfun,amin=-2,amax=2,apts=20,bmin=-2,bmax=2,bpts=20,color='black',name=' '):
u, v = np.linspace(amin,amax,apts), np.linspace(bmin,bmax,bpts)
path = snake(u,v)
r = [[rfun(u,v)[i] for (u,v) in path] for i in range(3)]
trace = Scatter3d(x=r[0],y=r[1],z=r[2],mode='lines',name=name,
line=Line(color=color,width=3))
return(trace)