title: Generate several subplots with a loop
body: <p>I want to show all average temperatures of each month in a small chart for every year. My first issue is printing the legend for the colder (blue) and warmer (respectively red) temperatures and giving colour to the chart itself.
  My second issue is connected with looping through the data, ending in getting the following error:
  <code>TypeError: unsupported operand type(s) for /: 'tuple' and 'int'</code>. The amount of the years doesn't always have to be an even number. How can I nicely represent that in the loop?</p>
  <p>How can I nake the chart like the picture underneath, including the coloured legend and chart.</p>
  <p>What I want:</p>
  <ul>
  <li>displaying all the years with all average temperatures of each month</li>
  <li>coloured legend and chart</li>
  <li>(It doesn't matter whether matloblib or seaborn)</li>
  </ul>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import matplotlib.pyplot as plt
  import pandas as pd
  d = {'year': [2001, 2001, 2001, 2001, 
                2002, 2002, 2002, 2002],
       'month': [1, 2,3,4,
                1,2,3,4],
       'temperature': [10,20,15,20,
                       20,10,5,10]}
  df = pd.DataFrame(data=d)
  
  df.head()
  
  
  fig, axs = plt.subplots(int(len(df.year.unique()) / 2), int(len(df.year.unique()) / 2))
  
  for i in enumerate(df.year.unique()):
      for j in range(int(i/2)):
          for k in range(int(i/2)):
              month = df['month'].unique()
              temperature = df[df['year'] == i].groupby('month')['temperature'].mean().values
              axs[j][k].bar(month, temperature)
  plt.show()
      
  
  
  </code></pre>
  <p><code>TypeError: unsupported operand type(s) for /: 'tuple' and 'int'</code></p>
  <p><a href="https://i.stack.imgur.com/91ahH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/91ahH.png" alt="enter image description here" /></a></p>