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

Question on sub_plotting in a square(ish), dynamically sized plot matrix

Hi,

First time poster, long time lurker :slight_smile:

I have a dataframe with a structure as such:

columns = names, time, date, measurement, measurement2, measurement3

I want to create a plot using sub_plots (or whatever you recommend) that loops through names column and makes plots of measurement1 vs measurement2.

Further I want the sub_plots to be roughly square shaped and dynamically adjustable (e.g. if i have 34 unique names i want to have a 6 x 6 shaped plot matrix and fill 34 of the 36 plots), and if i have 20 names i want it to be a 5x5 shape etc.

Where i’m struggling is how to generate a separate plot for each of the “name” variable and then how to properly place those unique plots into the correct row and column of the sub_plot matrix.

I’ve attempted to do this using make_subplots, but was hoping there is a smarter way to do this by concatenating the plots into a square shaped matrix, thoughts?

sample code (probably not working)

fig = make_subplots(rows=max_row, cols=max_col)

for i, name in enumerate(names,1):
    fig.add_trace(go.Scatter(x=df['measurement1'].loc[df.names==name],
                             y=df['measurement2'].loc[df.names==name],
                             name=name),
                    #row=don't know what to put here,
                    #col=don't know what to put herel,)