I canât figure out how to have a slider with a 3x3 subplots. I had to manually set the domain for each plot to position them because theyâre a mix of 2D and 3D plots.
I want the slider at the bottom or vertically on the left of the plots.
I havenât yet experimented with sliders associated to each subplot, but I think that a function like this one can work:
def get_sliders(x, y, len, nr_frames, label, prefix, duration=20):
return [dict(steps= [dict(method= 'animate',#Sets the Plotly method to be called when the
#slider value is changed.
args= [[ 'frame{}'.format(k) ],#Sets the arguments values to be passed to
#the Plotly method set in method on slide
dict(mode= 'immediate',
frame= dict( duration=duration, redraw= False ),
transition=dict( duration= 0)
)
],
label=label
) for k in range(nr_frames)],
transition= dict(duration= 0 ),
x=x,#slider starting position
y=y,
currentvalue=dict(font=dict(size=12),
prefix='Frame: ',
visible=True,
xanchor= 'center'
),
len=len)#slider length)
]
After defining the subplots configuration, inspect fig[âlayoutâ] and looking at the domain for each subplot you can define:
sliders=sliders=get_sliders(0, 0.525, len1, nr_frames1, label1, prefix1)+get_sliders(0.525, 0.525, len2, nr_frames2, label2, prefix2)+get_sliders(0, 0, 1, nr_frames, label3, prefix3) (here I used the domain for each subplot in https://plot.ly/~empet/1462).
!!! a) It is important to give different names to number of frames in each animation, in order
to pass the right one to get_sliders.
b) len1, len2, len3 should be chosen less than the length of x domain for each subplot.
Hey thanks for looking into this. I create the subplots same as you but for some reason all my subplots are in 1 row even though I specify 3. Here is the functions. Iâm trying to create 3x3 Surface plots for now because Heatmap is being buggy.
And the slider is hidden for some reason. I want one slider to control them all, at the bottom. If I look at one row (1x3) subplots, the slider is below the plot area; between the colorbar and the âExport to plot.lyâ and that space is empty when I do it with 3x3 even with fixed domains.
Can you please have a look and tell me what Iâm missing?
When you use the make_subplots you donât have to define the domain for each scene and they show up fine but mine donât. I was defining domain before when I had Heatmap and Surface thatâs why itâs commented out.
the dict figure is initialized with preliminary settings for its key, layout.
Just print figure['layout'] to inspect its keys-values.
When you insert this line:
figure['layout'] = layout
all initial settings disappear.
This is exactly as doing:
x=2 #initial setting
x=3
Now x=3
In order to keep the initial keys-values in figure['layout']
you have to update it with the new pairs, key-value (see as example, the last notebook where I defined mixed subplots).
As long as you use figure.append_trace() to assign traces to subplots,
there is no need to specify the scene in trace definition, as you did, because figure.append_trace(trace_name, i, j)
does it.