[Solved] Can someone help me rewrite this code (fig with multiple histograms) with a for loop or function?


You could create a list with the years and iterate over it:

years = ['1990', '1995', '2000', '2005', '2010', '2015']

plot_i = 1
for y in years:
  data = mmr[mmr['Year']==y]
  ax = fig.add_subplot(2,3,plot_i)
  ax.hist(data['MMR'], color="darkred", edgecolor="white")
  ax.set_title(y + ' MMR Distribution', fontweight="bold", loc="left")
  ax.spines['left'].set_visible(False)
  ax.spines['top'].set_visible(False)
  ax.spines['right'].set_visible(False)
  ax.spines['bottom'].set_visible(False)
  ax.tick_params(length=0)
  ax.set_xlim(0,3000,500)
  plot_i = plot_i + 1

1

solved Can someone help me rewrite this code (fig with multiple histograms) with a for loop or function?