title: How do I set each plotly subplot title during graph creation loop?
body: <p>I understand that if I want to set all of the subplot titles then I can do that when I declare the figure.</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import plotly.graph_objs as go
  from plotly.subplots import make_subplots
  
  fig = make_subplots(
      ###
      subplot_titles=['Plot 1', 'Plot 2', 'Plot 3', 'Plot 4', etc.]
  )
  </code></pre>
  <p>However, I create each subplot graph within a loop, and I think it would be easiest to set each subplot's title during that process. In my case, I created a groupby object based on date, and then I loop through each group (date) dataframe. Each dataframe is used to create the subplot graph, and I'd like the title to be the date. I understand that I <em>can</em> figure this out before the loop and set the subplot_titles as normal, but it seems like it'd be a one-liner within the loop. If it matters, the traces I'm adding are choropleths. I'm not going to include a working dataset since my code works fine- I just want to know what line of code I need to add.</p>
  <pre><code>#Create groupby object, splitting data frame into separate data frames based on 'State'
  death_counts_gbo = death_counts_by_week.groupby('End Week') 
  
  #Prepare subplots for choropleths
  rows = 4
  cols = 7
  fig = make_subplots(
      rows=rows, cols=cols,
      specs = [[{'type': 'choropleth'} for c in np.arange(cols)] for r in np.arange(rows)],
  )
      
  #Graph each state's data
  for i, (date, df) in enumerate(death_counts_gbo):
      fig.add_trace(go.Choropleth(
          locations=df['State Abbr'], # Spatial coordinates
          z = df['COVID-19 Deaths per 100k'].astype(float), # Data to be color-coded
          locationmode = 'USA-states', # set of locations match entries in `locations`
          colorscale = 'Reds',
          zmin = 0,
          zmax = 30,
          colorbar_title = &quot;Deaths per 100k&quot;,
          text = date.strftime('%m-%d-%Y')
      ), row=i//7+1, col=i%7+1)
      ### This is where I'd like to set the subplot's title to 'date' ###
  
  # Set title of entire figure
  # Set each subplot map for the USA map instead of default world map
  # Set each subplot map's lake color to light blue
  fig.update_layout(
      title_text = 'COVID-19 Deaths per 100k at week ending',
      **{'geo' + str(i) + '_scope': 'usa' for i in [''] + np.arange(2,len(death_counts_gbo)+1).tolist()},
      **{'geo' + str(i) + '_lakecolor': 'lightblue' for i in [''] + np.arange(2,len(death_counts_gbo)+1).tolist()},
  )
      
  fig.show()
  </code></pre>
  <p>EDIT: For my example, I can set the subplot titles during the figure declaration with the following kwarg:</p>
  <pre><code>subplot_titles = [date.strftime('%m-%d-%Y') for date in list(death_counts_gbo.groups.keys())]
  </code></pre>
  <p>However, for my own edification and if I have a future case where the determination of the subtitle is more involved, I would still like to know how to set it during the loop / after the figure declaration.</p>
  <p>EDIT2: Thanks to @rpanai I have a solution, though it required a change in my <code>make_subplots</code> declaration, in addition to a one-liner in the loop. He informed me that subtitles are annotations stored in <code>fig.layout.annotations</code> and that, while a list of subtitles may be provided to it, calculating the appropriate <code>x</code> and <code>y</code> coordinates might be a hassle. I worked around this issue by creating temporary subtitles and forcing <code>make_subplots</code> to calculate the <code>x</code> and <code>y</code> coordinates. I then updated the text in the loop.</p>
  <p>The updated <code>make_subplots</code> figure declaration (subplot_titles added):</p>
  <pre><code>fig = make_subplots(
      rows=rows, cols=cols,
      specs = [[{'type': 'choropleth'} for c in np.arange(cols)] for r in np.arange(rows)],
      subplot_titles = ['temp_subtitle' for date in np.arange(len(death_counts_gbo))]
  )
  </code></pre>
  <p>One-liner (first line of the for-loop):</p>
  <pre><code>fig.layout.annotations[i]['text'] = date.strftime('%m-%d-%Y')
  </code></pre>