title: Can someone help me rewrite this code (fig with multiple histograms) with a for loop or function?
body: <p>I looked at a similar post but am still struggling with it.  You don't have to write out the whole code if you don't want.  But a syntactical guide would be helpful.  Here is my lengthy manual approach:</p>
  
  <pre><code># Grid of MMR distributions by every 5 years
  mmr_1990 = mmr[mmr['Year']=='1990']
  mmr_1995 = mmr[mmr['Year']=='1995']
  mmr_2000 = mmr[mmr['Year']=='2000']
  mmr_2005 = mmr[mmr['Year']=='2005']
  mmr_2010 = mmr[mmr['Year']=='2010']
  mmr_2015 = mmr[mmr['Year']=='2015']
  
  year_list = [mmr_1990, mmr_1995, mmr_2000, mmr_2005, mmr_2010, mmr_2015]
  
  fig = plt.figure(figsize=(12,8))
  
  ax1 = fig.add_subplot(2,3,1)
  ax2 = fig.add_subplot(2,3,2)
  ax3 = fig.add_subplot(2,3,3)
  ax4 = fig.add_subplot(2,3,4)
  ax5 = fig.add_subplot(2,3,5)
  ax6 = fig.add_subplot(2,3,6)
  
  #1990
  ax1.hist(mmr_1990['MMR'], color='darkred', edgecolor='white')
  ax1.set_title('1990 MMR Distribution', fontweight='bold', loc='left')
  ax1.spines['left'].set_visible(False)
  ax1.spines['top'].set_visible(False)
  ax1.spines['right'].set_visible(False)
  ax1.spines['bottom'].set_visible(False)
  ax1.tick_params(length=0)
  ax1.set_xlim(0,3000,500)
  
  #1995
  ax2.hist(mmr_1995['MMR'], color='darkred', edgecolor='white')
  ax2.set_title('1995 MMR Distribution', fontweight='bold', loc='left')
  ax2.spines['left'].set_visible(False)
  ax2.spines['top'].set_visible(False)
  ax2.spines['right'].set_visible(False)
  ax2.spines['bottom'].set_visible(False)
  ax2.tick_params(length=0)
  ax2.set_xlim(0,3000,500)
  
  #2000
  ax3.hist(mmr_2000['MMR'], color='darkred', edgecolor='white')
  ax3.set_title('2000 MMR Distribution', fontweight='bold', loc='left')
  ax3.spines['left'].set_visible(False)
  ax3.spines['top'].set_visible(False)
  ax3.spines['right'].set_visible(False)
  ax3.spines['bottom'].set_visible(False)
  ax3.tick_params(length=0)
  ax3.set_xlim(0,3000,500)
  
  #2005
  ax4.hist(mmr_2005['MMR'], color='darkred', edgecolor='white')
  ax4.set_title('2005 MMR Distribution', fontweight='bold', loc='left')
  ax4.spines['left'].set_visible(False)
  ax4.spines['top'].set_visible(False)
  ax4.spines['right'].set_visible(False)
  ax4.spines['bottom'].set_visible(False)
  ax4.tick_params(length=0)
  ax4.set_xlim(0,3000,500)
  
  #2010
  ax5.hist(mmr_2010['MMR'], color='darkred', edgecolor='white')
  ax5.set_title('2010 MMR Distribution', fontweight='bold', loc='left')
  ax5.spines['left'].set_visible(False)
  ax5.spines['top'].set_visible(False)
  ax5.spines['right'].set_visible(False)
  ax5.spines['bottom'].set_visible(False)
  ax5.tick_params(length=0)
  ax5.set_xlim(0,3000,500)
  
  #2015
  ax6.hist(mmr_2015['MMR'], color='darkred', edgecolor='white')
  ax6.set_title('2015 MMR Distribution', fontweight='bold', loc='left')
  ax6.spines['left'].set_visible(False)
  ax6.spines['top'].set_visible(False)
  ax6.spines['right'].set_visible(False)
  ax6.spines['bottom'].set_visible(False)
  ax6.tick_params(length=0)
  ax6.set_xlim(0,3000,500)
  ax6.text(600, 50, 'Note how the bins \nshifted left over time.', size=12)
  </code></pre>
  
  <p>The output should look like this:
  <a href="https://i.stack.imgur.com/bBS3L.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>The data is from UNICEF, under Access the Data <a href="https://data.unicef.org/topic/maternal-health/maternal-mortality/" rel="nofollow noreferrer">https://data.unicef.org/topic/maternal-health/maternal-mortality/</a></p>