Black Lives Matter. Please consider donating to Black Girls Code today.

Slider hidden under subplots

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.

Cheers

@lordlycastle

  1. Mixed 2d and 3d subplots can be defined as in this notebook: https://plot.ly/~empet/14625

  2. 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.

Here’s what they look like.

@lordlycastle

  1. When you define

    figure = tools.make_subplots(rows=3,
                              cols=3,
                              specs=...,
                              )
    

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 :frowning:

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).

  1. 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.

@empet Thanks. Updating layout fixes the issue. I don’t set the scene when defining the traces, only when defining frames. Maybe you misread it.