Hi,
I’m working on making a rotating 3D plot in plotly. I found the following topic in this forum:
https://community.plotly.com/t/how-to-animate-a-rotation-of-a-3d-plot/20974
The help looked really promising, but like the last person commenting I have some trouble determining exactly where the different parts are supposed to go! Please help me find out what I am doing incorrectly.
Here is my minimal working example:
import plotly.graph_objects as go
import numpy as np
# Helix equation
t = np.linspace(0, 10, 50)
x, y, z = np.cos(t), np.sin(t), t
data=[go.Scatter3d(x=x, y=y, z=z, mode='markers')]
x_eye = -1.25
y_eye = 2
z_eye = 0.5
layout = go.Layout(
title='Animation Test',
width=600,
height=600,
scene=dict(camera=dict(eye=dict(x=x_eye, y=y_eye, z=z_eye))),
updatemenus=[dict(type='buttons',
showactive=False,
y=1,
x=0.8,
xanchor='left',
yanchor='bottom',
pad=dict(t=45, r=10),
buttons=[dict(label='Play',
method='animate',
args=[None, dict(frame=dict(duration=2, redraw=False),
transition=dict(duration=0),
fromcurrent=True,
mode='immediate'
)]
)
]
)
]
)
def rotate_z(x, y, z, theta):
w = x+1j*y
return np.real(np.exp(1j*theta)*w), np.imag(np.exp(1j*theta)*w), z
frames=[]
for t in np.arange(0, 6.26, 0.1):
xe, ye, ze = rotate_z(x_eye, y_eye, z_eye, -t)
frames.append(dict(layout=dict(scene=dict(camera=dict(eye=dict(x=xe, y=ye, z=ze))))))
fig = go.Figure(data=data, layout=layout, frames=frames)
fig.show()