title: Plotly : can't create subplots the right way
body: <p>I have currently chart where I display the price of an asset and add some moving average traces. Now I want to add other indicators to the chart ( OBV, MACD, RSI ). Every time I call one of these three I would like my current chart to be fractioned in subplots. Let say I add OBV, my display will 2 subplots ( the price above and OBV below ). Now if I want to add MACD, it should display the price above, OBV below in the middle and MACD below ( 3 subplots ). I would like potentially to do that for any number of indicators.
  I tried to do something but it doesn't work correctly.</p>
  <pre><code>def display(value, timeframes, indicators, start_date, end_date):
      st.write(f&quot;&quot;&quot;
      # {value}
      Price *chart*&quot;&quot;&quot;)
      df = pd.read_csv(f'data/{timeframes}/{value}-{timeframes}-data.csv', parse_dates=['timestamp'], index_col='timestamp')
  
      if start_date &lt; end_date:
         df = df[start_date : end_date]
      else:
         st.error('Error: End date must fall after start date.')
  
      fig = make_subplots(rows = 4, cols = 1, shared_xaxes = True, vertical_spacing = 0.05, 
                      specs=[[{&quot;secondary_y&quot;: True}], [{&quot;secondary_y&quot;: True}], [{&quot;secondary_y&quot;: True}], [{&quot;secondary_y&quot;: True}]])
  
      trace_price = fig.add_trace(
                      go.Candlestick(
                            x = df.index,
                            open = df['open'],
                            high = df['high'],
                            low = df['low'],
                            close = df['close'],
                            name = 'Candlestick'),
                      
                            secondary_y = True, 
                            row = 1, col = 1
                )
  
  
  
     for indi in indicators:
  
  
  
      #FIRST SUBPLOT  obj = indicators.indicators(df, range_indi, periods)
      
      if indi.startswith('SMA'):
          
          sma_trace = go.Scatter( 
                            x=df.index, y=indicator.simple_moving_average(df,int(indi[3:])), 
                            line=dict(color= np.random.choice(colors_sma, replace = False), width=1),
                            name = f'SMA{indi[3:]}'
                            )
          
          fig.add_trace(sma_trace, secondary_y = True, row = 1, col = 1)
  
      if indi.startswith('WMA'): 
          wma_trace = go.Scatter(
                            x=df.index, y=indicator.weighted_moving_average(df,int(indi[3:])), 
                            line=dict(color=np.random.choice(colors_wma, replace = False), width=1),
                            name = f'WMA{indi[3:]}'
                            )
  
          fig.add_trace(wma_trace, secondary_y = True,row = 1, col = 1) 
  
      if indi.startswith('EMA'):
          ema_trace = go.Scatter(
                            x=df.index, y=indicator.exponential_moving_average(df,int(indi[3:])), 
                            line=dict(color=np.random.choice(colors_ema, replace = False), width=1),
                            name = f'EMA{indi[3:]}'
                            )
  
          fig.add_trace(ema_trace, secondary_y = True,row = 1, col = 1)
  
  
      # SECOND SUBPLOT
  
      if indi.startswith('OBV'):
          obv_trace = go.Scatter(
                            x=df.index, y= indicator.on_balance_volume(df, int(indi[3:])), line=dict(color='yellow', width=1),
                            name = f'OBV{indi[3:]}'
                            )
  
          fig.add_trace(obv_trace, row = 2, col = 1)
  
  
      # THIRD SUBPLOT
          
  
      if indi.startswith('RSI'):
          
          fig.add_trace(
                go.Scatter(
                    x=df.index, y=indicator.relative_strength_index(df, periods = 14),
                    name='RSI', marker_color='#109618'
                ), row=3, col=1,
          )
      
          fig.add_trace(
                go.Scatter(
                    x=df.index, y=[70] * len(df.index),
                    name='Overbought', marker_color='#109618',
                    line = dict(dash='dot'), showlegend=False,
                ), row=3, col=1,
          )
      
          fig.add_trace(
                go.Scatter(
                    x=df.index, y=[30] * len(df.index),
                    name='Oversold', marker_color='#109618',
                    line = dict(dash='dot'),showlegend=False,
                ),row=3, col=1,
          )
                            
      # FOURTH SUBPLOT
  
      if indi.startswith('MACD'):
          macd, macd_s, macd_h = indicator.moving_average_convergence_divergence(df)
          #fast signal
          fig.add_trace(
                go.Scatter(
                      x = df.index, y = macd, 
                      line=dict(color='#ff9900', width=2), 
                      name = 'macd',
                ), row = 4, col = 1,
          )
          #slow signal
          fig.add_trace(
                go.Scatter(
                      x = df.index, y = macd_s, 
                      line=dict(color='#000000', width=2), 
                      name = 'macd',
                ), row = 4, col = 1,
          )
          # Colorize the histogram values
          colors = np.where(macd_h &lt; 0, '#000', '#ff9900')
          # Plot the histogram
          fig.add_trace(
                go.Bar(
                      x = df.index, y =  macd_h, 
                      name='histogram', marker_color=colors,
                ), row = 4, col = 1, 
          )
      
  
          
      
  
       fig.update_layout(width= 900,height = 700)  
       fig.update_layout(xaxis_rangeslider_visible=False)     
       fig.update_xaxes(showticklabels=True )
       # Set y-axes titles
       fig.update_yaxes(title_text=&quot;&lt;b&gt;Volume&lt;/b&gt;&quot;, secondary_y=False)
       fig.update_yaxes(title_text=&quot;&lt;b&gt;Price&lt;/b&gt;&quot;, secondary_y=True)
  
  price = st.plotly_chart(fig, width= 900,height = 700)
  return price
  </code></pre>
  <p>For the moment my code will display the price chart but whenever I call OBV, MACD or RSI, they will be displayed on the right place but the price chart keeps is original shape. What should I do ?</p>