# 3D surface animation the diameter of a wire/cylinder

Hello,

I am trying to recreate a 3D model of a wire and add a slider for one the axis.
I am able to this with the code below (sorry for the length, I didnt have time to remove/correct things yet since I am still in the first part of my project).
As I did not see anything like the range slider, I tried using sliders with for each frame a different part of the wire.
However I cant get this to work and I cant find the error. I based this code on codes that I found:

â€“
import plotly.graph_objs as go
import random
import plotly.plotly as py
import numpy as np
MaxDiameter=s = np.random.uniform(2.85,2.95,1000)
MinDiameter=s = np.random.uniform(2.75,2.85,1000)
x=[]
y=[]
z=[]

xx=[]
yy=[]
zz=[]

xxlist=[]
yylist=[]
zzlist=[]
pixels=20
t = np.linspace(0, 2 * np.pi, pixels)#gives 2*20
iteration=0
seconditer=0
framesize=20

for Max,Min in zip(MaxDiameter,MinDiameter):
if iteration<(framesize+seconditer) and iteration>=(0+seconditer):
print(iteration)
us = np.linspace(0, 2 * np.pi, pixels)
us, zs = np.meshgrid(us, zs)

``````#     xs = (Dia+Ovality) * np.cos(us)
#     ys = (Dia-Ovality) * np.sin(us)
xs = Max* np.cos(us)
ys = Min * np.sin(us)
x.append(xs)
y.append(ys)
z.append(zs)
else:
print('hmm ',iteration)
seconditer+=framesize
print('second',seconditer)
``````

# zz=ys*0

``````    for a,s,d,leng in zip(x,y,z,range(len(z))):
if leng==0:
zz=d
yy=s
xx=a
continue
zz=np.concatenate((zz,d))
yy=np.concatenate((yy,s))
xx=np.concatenate((xx,a))
zz,xx=xx,zz#swap
xxlist.append(xx)
yylist.append(yy)
zzlist.append(zz)
x=[]
y=[]
z=[]

xx=[]
yy=[]
zz=[]
``````

for a,s,d,leng in zip(x,y,z,range(len(z))):
if leng==0:
zz=d
yy=s
xx=a
continue
zz=np.concatenate((zz,d))
yy=np.concatenate((yy,s))
xx=np.concatenate((xx,a))
zz,xx=xx,zz#swap
xxlist.append(xx)
yylist.append(yy)
zzlist.append(zz)
x=[]
y=[]
z=[]
xx=[]
yy=[]
zz=[]
surface = go.Surface(x=xxlist[1], y=yylist[1], z=zzlist[1])#cartensian coordiantes
data = [surface]

datalist=[]
for v in range(len(xxlist)):
surface = go.Surface(x=xxlist[v], y=yylist[v], z=zzlist[v])
thedata = [surface]
datalist.append(thedata)
theframes=[dict(data= datalist[k],
traces= [0],
name=â€˜frame{}â€™.format(k)
) for k in range(len(xxlist))]

sliders=[dict(steps= [dict(method= â€˜animateâ€™,
args= [[ â€˜frame{}â€™.format(k) ],
dict(mode= â€˜immediateâ€™,
frame= dict( duration=50, redraw= False ),
transition=dict( duration= 0)
)
]
) for k in range(len(xxlist))],
transition= dict(duration= 0 ),
x=0,
y=0,
currentvalue=dict(font=dict(size=12),
prefix='Time: ',
visible=True,
xanchor= â€˜centerâ€™
),
len=1.0))
]

rangehx=4
rangelx=-4
layout = go.Layout(
title=â€˜Wireâ€™,
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)â€™,
range=[rangelx,rangehx]
),
zaxis=dict(
gridcolor=â€˜rgb(255, 255, 255)â€™,
zerolinecolor=â€˜rgb(255, 255, 255)â€™,
showbackground=True,
backgroundcolor=â€˜rgb(230, 230,230)â€™,
range=[rangelx,rangehx]
),

``````),
y=0,
x=1.15,
xanchor='right',
yanchor='top',
buttons=[dict(label='Play',
method='animate',
args=[None,
dict(frame=dict(duration=30,
redraw=True),
transition=dict(duration=0),
fromcurrent=True,
mode='immediate'
)
]
)
]
)
],
sliders=sliders,
``````

fig = go.Figure(data=data, layout=layout,frames=theframes)
py.iplot(fig, filename=â€˜Diameter3â€™)