Camera fly doesn't work in plotly.offline with python? help please;)

Hi! Can anyone spot an error in the following code? The idea is to animate a camera fly above some surface. The code seems to work in a jupyter notebook, but the animation gets really slow. In an offline mode simply nothing changes…;( Frustration x() Any ideas?: please?:wink:


import plotly
from plotly.offline import download_plotlyjs, plot

#yes, i actually do have m credentials here
plotly.tools.set_credentials_file(username=’’, api_key=’’)

y=np.linspace(0,6*np.pi,200)
x=np.zeros(len(y))#([i*2, i*2+1])
z=np.sin(y)

traces=[dict(
z=[[cz,cz] for cz in z],
x=[[cx,cx+1] for cx in x],
y=[[cy,cy] for cy in y],
colorscale=[ [i, ‘rgb(100,100,255)’] for i in np.arange(0,1.1,0.1) ],
showscale=False,
type=‘surface’,
)]

malpha=np.linspace(0,90,5)
malpha=[float(xx)/180*3.1415 for xx in malpha]

mfr=[]
for ii in malpha:
mcam= dict(
up=dict(x=-np.sin(ii), y=0, z=np.cos(ii)),
center=dict(x=0, y=0, z=0),
eye=dict(x=2.5np.cos(ii), y=0, z=2.5np.sin(ii)),
)
mfr.append(dict(layout= dict(scene=dict(camera= mcam),title=(‘Cur angle:’+str(ii/3.1415*180))) ))

cam0 = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=2.5, y=0, z=0)
)

fig = {‘data’:traces,
‘frames’:mfr,
‘layout’:{ ‘scene’:{‘camera’:cam0},
‘updatemenus’: [{‘type’: ‘buttons’,
‘buttons’: [{‘label’: ‘Play!’, ‘method’: ‘animate’, ‘args’:[None]}]}],
‘title’:‘Ribbon Plot’} }
plot(fig,filename=‘ribbon-plot-python2’)

@kostjia Your animation works fine with iplot: http://nbviewer.jupyter.org/gist/empet/b33cf8fa993055359b18d1e77d0e10d2 With your code for updatemenus it was slow because you didn’t set frame duration and it played with the default duration=500, which is indeed very slow.

However plot(fig) generates a static plot. I couldn’t find any reason for this behaviour.
It appears that offline animation works either with iplot or with plot. When I animate a surface it works with plot, but not with iplot. I opened an issue here https://github.com/plotly/plotly.py/issues/702 but no answer or fix yet.

1 Like

@empet Thanks for your help! The reason i used plot is because although it works with iplot it’s still to slow even if you set the frame duration… My goal was a smooth flight with more data and more frames (yes, i also tried setting transition times), which does not seem to be possible with iplot…