Hi @anastasia.m,
Welcome to plotly forum!! Could you be more precise, what do you mean by “switching from a static size of 3 to dynamic sizes”?
I’ve just experimented an animation that changes from frame to frame, the marker size and color, and it works fine. What is your working plotly version?
Here is my code based on your data:
import numpy as np
import pandas as pd
import plotly.graph_objects as go
colors = ['#531e7d', '#5e59b0', '#6d91bf', '#a7c0ca', '#cfb19c', '#bf735d', '#9d3a4f',
"rgb(255, 127, 14)",
"rgb(44, 160, 44)",
"rgb(214, 39, 40)"]
d = {'x': -2.3+np.random.rand(10),
'y': 1-2*np.random.rand(10),
'z': 1.5*np.random.rand(10),
'i': ['a', 'b', 'ccc', 'dev', 'fyi', 'calc', 'comp', 'miao', 'yes', 'nono'],
'marker_size': np.random.randint(15, 25, size=10),
'colour': colors}
df = pd.DataFrame(d)
data =[go.Scatter3d(
x=df['x'],
y=df['y'],
z=df['z'],
text=df['i'],
textposition="top center",
mode='markers',
marker=dict(size=df["marker_size"], color=df["colour"]),
name=str(df['i'])
)
]
h = 0.25
xm, xM = df['x'].min()-h, df['x'].max()+h
ym, yM = df['y'].min()-h, df['y'].max()+h
zm, zM = df['z'].min()-h, df['z'].max()+h
frames = [ dict(data=[dict(type='scatter3d',
marker=dict(size = np.random.randint(15, 30, size=10).tolist(),
color = np.random.permutation(colors)))],
traces='0') for k in range(30)]
layout =go.Layout(width=600, height=600,
scene=dict(
xaxis =dict(range=[xm, xM]),
yaxis=dict(range=[ym, yM]),
zaxis=dict(range=[zm, zM]),
camera=dict(eye=dict(x=1.25, y=1.55, z= 1))),
updatemenus=[dict(type='buttons', showactive=False,
y=0,
x=1.05,
xanchor='right',
yanchor='top',
pad=dict(t=0, r=10),
buttons=[dict(label='Play',
method='animate',
args=[None,
dict(frame=dict(duration=50,
redraw=True),
transition=dict(duration=0),
fromcurrent=True,
mode='immediate')
]
)
]
)
] )
fig=go.Figure(data=data, layout=layout, frames=frames)
fig.show()