title: how to plot multiple charts using make_subplot in plotly and python
body: <p>I am trying to plot multiple charts using <strong>plotly</strong> and <strong>make_subplot</strong> where I want to plot 5 <strong>pie charts</strong> that are created using the iteration for loop. And 1 <strong>bar chart</strong> where the bar chart will take <strong>colspan = 2</strong></p>
  <h1>dataframe sample:</h1>
  <pre><code>eventtype_name    date    eventmohafaza_name   number       groups
  watch movie     8/14/2020   loc1                 25         group1
  stay at home    8/13/2020   loc2                 20         group2
  swimming        8/13/2020   loc2                 25         group4
  camping         8/13/2020   loc3                 20         group3
  meeting         8/13/2020   loc4                 40         group5
  meeting         8/13/2020   loc5                 20         group2
  watch movie     8/14/2020   loc4                 25         group1
  stay at home    8/13/2020   loc1                 20         group2
  swimming        8/13/2020   loc5                 25         group4
  camping         8/13/2020   loc4                 20         group3
  meeting         8/13/2020   loc3                 30         group5
  meeting         8/13/2020   loc5                 33         group2
  </code></pre>
  <p>The problem is in when I assign the <strong>rows</strong> and <strong>columns</strong> and try to use <strong>specs</strong> parameter the system crash and display the below error.</p>
  <pre><code>This is the format of your plot grid:
  [ (1,1)     ]  [ (1,2)     ]  [ (1,3)     ]
  [ (2,1)     ]  [ (2,2)     ]  [ (2,3)     ]
  [ (3,1)     ]  [ (3,2) x,y           -    ]
  
  ---------------------------------------------------------------------------
  IndexError                                Traceback (most recent call last)
  f:\aienv\lib\site-packages\plotly\subplots.py in _set_trace_grid_reference(trace, layout, grid_ref, row, col, secondary_y)
     1318     try:
  -&gt; 1319         subplot_refs = grid_ref[row - 1][col - 1]
     1320     except IndexError:
  
  IndexError: list index out of range
  
  During handling of the above exception, another exception occurred:
  
  Exception                                 Traceback (most recent call last)
  &lt;ipython-input-108-831d326e87b8&gt; in &lt;module&gt;
       59                          rotation=90),
       60      row=row,
  ---&gt; 61      col=col
       62     )
       63 
  
  f:\aienv\lib\site-packages\plotly\basedatatypes.py in add_trace(self, trace, row, col, secondary_y)
     1650             rows=[row] if row is not None else None,
     1651             cols=[col] if col is not None else None,
  -&gt; 1652             secondary_ys=[secondary_y] if secondary_y is not None else None,
     1653         )
     1654 
  
  f:\aienv\lib\site-packages\plotly\basedatatypes.py in add_traces(self, data, rows, cols, secondary_ys)
     1764         if rows is not None:
     1765             for trace, row, col, secondary_y in zip(data, rows, cols, secondary_ys):
  -&gt; 1766                 self._set_trace_grid_position(trace, row, col, secondary_y)
     1767 
     1768         # Make deep copy of trace data (Optimize later if needed)
  
  f:\aienv\lib\site-packages\plotly\basedatatypes.py in _set_trace_grid_position(self, trace, row, col, secondary_y)
     1847         grid_ref = self._validate_get_grid_ref()
     1848         return _set_trace_grid_reference(
  -&gt; 1849             trace, self.layout, grid_ref, row, col, secondary_y
     1850         )
     1851 
  
  f:\aienv\lib\site-packages\plotly\subplots.py in _set_trace_grid_reference(trace, layout, grid_ref, row, col, secondary_y)
     1320     except IndexError:
     1321         raise Exception(
  -&gt; 1322             &quot;The (row, col) pair sent is out of &quot;
     1323             &quot;range. Use Figure.print_grid to view the &quot;
     1324             &quot;subplot grid. &quot;
  
  Exception: The (row, col) pair sent is out of range. Use Figure.print_grid to view the subplot grid. 
  </code></pre>
  <h1>code:</h1>
  <pre><code>import plotly.graph_objs as go
  from plotly.subplots import make_subplots
  import plotly.express as px
  import pandas as pd
  
  
  
  df = pd.read_excel(file)
  lst = list(df.groupby('eventmohafaza_name'))
  
  
  rows = 3
  cols = 3
  
  subplot_titles = [l[0] for l in lst]
  
  
  specs=[
             [{&quot;type&quot;: &quot;pie&quot;},{&quot;type&quot;: &quot;pie&quot;},{&quot;type&quot;: &quot;pie&quot;}],
             [{&quot;type&quot;: &quot;pie&quot;},{&quot;type&quot;: &quot;pie&quot;},{&quot;type&quot;: &quot;pie&quot;}],
             [{&quot;type&quot;: &quot;pie&quot;},{&quot;type&quot;: &quot;bar&quot;,'colspan':2},None],
        ]
  
      
  fig = make_subplots(
          rows=rows,
          cols=cols,
          subplot_titles=subplot_titles,
          specs=specs,
          
          print_grid=True
  )
  
  for i, l in enumerate(lst):
      row = i // cols + 1
      col = i % (rows + 1) + 1
      d = l[1]
     
      fig.add_trace(go.Pie(labels=d[&quot;eventtype_name&quot;],
                           values = d[&quot;number&quot;],
                           hovertemplate = &quot;%{label}: &lt;br&gt;Value: %{value} &quot;,
                           showlegend=True,
                           textposition='inside',
                           rotation=90),
       row=row,
       col=col    
      )
      
  group_event_groups = df.groupby([df['eventmohafaza_name'],df['eventtype_name']]).size().unstack()    
  for x in group_event_groups.columns: 
      fig.add_trace(go.Bar(name=str(x), x=group_event_groups.index, y=group_event_groups[x],showlegend=False), row=3, col=2)
      
  fig.update_layout(height = 1000,
                    width = 900,
                    autosize = False,
                    title=&quot;Population by Continent&quot;, 
                    title_x=0.5)
  fig.show()
  </code></pre>
  <p><strong>the expected result is  5 pie charts and one bar chart</strong></p>