title: Getting default x-tick label text to use as indices to update tick labels with other text
body: <p>My intention: Plot some stuff, get the numbers corresponding to the default x-tick labels, and use these to index a list of dates so that I can put those dates in place of the default labels. </p>
  
  <p>Imagine I have two lists:</p>
  
  <pre><code>my_data = range(30)
  dates_ls = ['date_str1', 'date_str2', ... , 'date_str30']
  </code></pre>
  
  <p>I want to plot this data, then replace the x-ticks with the appropriate date from <code>dates_ls</code>, which just means indexing <code>dates_ls</code> with the numbers from the default x-tick labels.</p>
  
  <p>EDIT: So, the problem appears to be somehow due to the fact that I'm in a for loop:</p>
  
  <pre><code>dates_ls = ['dates_' + str(x+1) for x in range(30)]
  metrics_ls = ['sessions', 'pageviews']
  URL_names = ['URL_1', 'URL_2']
  DataDict_final = dict()
  for name in URL_names:
      DataDict_final[name] = {metric: [] for metric in metrics_ls}
  DataDict_final['URL_1']['sessions'] = range(30) # manually define for this example
  DataDict_final['URL_1']['pageviews'] = range(30)
  DataDict_final['URL_2']['sessions'] = range(30)
  DataDict_final['URL_2']['pageviews'] = range(30)
  
  for cur_page in URL_names:
  
     # plot
     fig, ax = plt.subplots()
     for i, cur_metric in enumerate(metrics_ls):
         data2plot = DataDict_final[cur_page] [cur_metric]       
         ax.plot(data2plot, label=cur_metric)
  
     # x and y axis limits and labels
     ax.set_xlim(0, len(DataDict_final[cur_page] [cur_metric])-1)    
     x_labs1 = [int(label.get_position()[0]) for label in ax.get_xticklabels()]
     x_labs2 = [dates_ls[x] for x in x_labs1]
     ax.set_xticklabels(x_labs2, fontsize=8, rotation=45, ha='right')
  </code></pre>
  
  <p>In the above, I'm looping through URL_names and metrics_ls, which are lists of dictionary keys that allow me to get data2plot, which is just a list of numbers. If I highlight and run the code with the for loop it works fine, but if I run the entire loop, producing multiple figures, x_labs1 ends up being a list of 0s, and therefore all my x-tick labels are the same, each one the first item in dates_ls.</p>