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 curve(rfun,tmin=-2,tmax=2,tpts=200,color='black'):
domain = np.linspace(tmin,tmax,tpts)
r = [[rfun(t)[i] for t in domain] for i in range(3)]
trace = Scatter3d(x=r[0],y=r[1],z=r[2],mode='lines',
line=Line(color=color,width=3))
return(trace)
tri_x=lambda t:(4-5*t if 0<=t<=1 else
-1+6*(t-1) if 1<=t<=2 else
5-(t-2))
tri_y=lambda t:(2*t if 0<=t<=1 else
2+3*(t-1) if 1<=t<=2 else
5-5*(t-2))
tri_z=lambda t:(5-2*t if 0<=t<=1 else
3+2*(t-1) if 1<=t<=2 else
5)
tri=[curve(lambda t:(tri_x(t),tri_y(t),tri_z(t)),tmin=0,tmax=3,color='black')]
py.iplot(Figure(data=Data(tri)))
cubic=[curve(lambda t:(t,t**2,t**3),tmin=-1.5,tmax=1.5,color='black')]
py.iplot(Figure(data=Data(cubic)))
helices=[curve(lambda t: (r*cos(w*t),r*sin(w*t),t),tmin=0,tmax=4*pi,color=c)
for (r,w,c) in ((5,1,'red'),(3,3,'green'),(1,10,'blue'))]
py.iplot(Figure(data=Data(helices)))
orange_peel=[curve(
lambda t: (cos(20*t)*sin(t),sin(20*t)*sin(t),cos(t))
,tmin=0,tmax=pi,color='orange')]
py.iplot(Figure(data=Data(orange_peel)))