title: Pandas Comparing hourly multiple year data in one plot
body: <p>So I have a pandas dataframe, called year, on this form:</p>
  
  <pre><code>                           discharge (m^3/s)  
  date                                                                   
  2016-01-01 00:00:00           17.6930
  2016-01-01 01:00:00           17.3247
  2016-01-01 02:00:00           17.2436
  2016-01-01 03:00:00           17.5696
  2016-01-01 04:00:00           16.4074
  2016-01-01 05:00:00           17.5696
  2016-01-01 06:00:00           17.0420            
  ....
  2017-12-31 20:00:00           10.5911           
  2017-12-31 21:00:00           10.5620          
  2017-12-31 22:00:00           10.7374          
  2017-12-31 23:00:00           10.5620 
  </code></pre>
  
  <p>The dataset contains discharge data for several years and I want to do a plot comparing f.ex. the month of january for the years 2016 and 2017.</p>
  
  <p>My attempts thus far has been to extract the wanted months and just plotting them on top of each other. But this does not work as you can see in this picture:</p>
  
  <p><a href="https://i.stack.imgur.com/AP1aJ.png" rel="nofollow noreferrer">Attempt plot 1</a></p>
  
  <p>My code for this was:</p>
  
  <pre><code># Comparison full months
  def plotmonthdischarge(month, years, number_of_years):
      df = pd.read_csv('resources\FinVannføringEidsfjordvatn.csv', encoding = 'ISO-8859-1',sep=';')
      df['date'] = pd.to_datetime(df['date'],dayfirst=True)
      df = df.set_index(df['date'])
      df['Day Of Year'] = df['date'].dt.dayofyear
      df = df.drop(['date'], axis = 1)
      df = df.replace(to_replace='-9999', value = np.NaN)
  
  
      fig, ax = plt.subplots()
  
      # For a starting year 2016 and a 1 following year
      # Call example:
      # plotmonthdischarge(1,[2016],2)
      if len(years) == 1:
          start_year = years[0]
          for i in range(number_of_years):
              year = df['{0}-{1}-01 00:00:00'.format(start_year+i,month):'{0}-{1}-31 23:59:59'.format(start_year+i,month)]
              ax.plot(year['discharge (m^3/s)'], label = 'Year {}'.format(start_year+i))
  
      # Just for plotting(ignore)
      formatted_list = ['{:&gt;3}' for i in range(number_of_years)] 
      string_of_years = ', '.join(formatted_list).format(*[start_year+i for i in range(number_of_years)])
      plt.title('Comparison plot of years {}'.format(string_of_years))
  
      # Specific years  2006 and 2017
      # Call example:
      # plotmonthdischarge(1,[2006,2017],1)
      if len(years) &gt; 1:
          number_of_years = 1
          for item in years:
              year = df['{0}-{1}-01 00:00:00'.format(item,month):'{0}-{1}-31 23:59:59'.format(item,month)]
              ax.plot(year['Day Of Year'],year['discharge (m^3/s)'], label = 'Year {}'.format(item))
  
      # Just for plotting(ignore)
      formatted_list = ['{:&gt;3}' for item in years] 
      string_of_years = ', '.join(formatted_list).format(*years)
      plt.title('Comparison plot of years {}'.format(string_of_years))
      print(year)
  
      plt.suptitle(r'Discharge $m^{3}s^{-1}$')
      plt.ylabel(r'Discharge $m^{3}s^{-1}$')
      plt.legend()
      plt.grid(True)
  
  plotmonthdischarge(1,[2015,2016],1)
  </code></pre>
  
  <p>My next attempt was with something I found in other posts</p>
  
  <pre><code>df['Day Of Year'] = df['date'].dt.dayofyear
  </code></pre>
  
  <p>and then plotting over all the days in the month: </p>
  
  <pre><code> ax.plot(year['Day Of Year'],year['discharge (m^3/s)'], label = 'Year {}'.format(item))
  </code></pre>
  
  <p>This worked okay except it seems like only one or so points per day gets registered which is bad since I'm working with hourly data.</p>
  
  <p><a href="https://i.stack.imgur.com/cyMj7.png" rel="nofollow noreferrer">Attempt plot 2</a></p>
  
  <p>Also tried removing year from the datetime (my index) and plotting over a datetime index with only month, day and hours, but with no real success.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>Example plot of how the plot of a single year (2015,january) would look like.</p>
  
  <p><a href="https://i.stack.imgur.com/nsmKo.png" rel="nofollow noreferrer">Correct plot I get of only one year</a></p>