'Create subplots with plotly using a loop

Is there a way to create a subplot with Plotly Express using a for to plot the data? I've tried some things here but nothing worked as expected. This is my last try:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=int(len(unique_pds)/2), cols=2)

for pds in unique_pds:
    fig.add_trace(
        go.Histogram(x=df[(df['Resolved'] >= resolved_date) &
        (df['Components'].astype(str).str.contains(components)) &
        (df['planned_effort'] == pds)]['lead_time']
                     )
    ).show()

The solution works almost perfectly, but the problem is that it is generating various subplots separated. I need all of them to be under the same subplot.

Thanks for the help. Marcelo



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source