nodes: 0, module; 1, function_definition; 2, function_name:calendarplot; 3, parameters; 4, block; 5, identifier:data; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, dictionary_splat_pattern; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, if_statement; 21, expression_statement; 22, expression_statement; 23, comment:# We explicitely resample by day only once. This is an optimization.; 24, if_statement; 25, expression_statement; 26, expression_statement; 27, expression_statement; 28, for_statement; 29, comment:# In a leap year it might happen that we have 54 weeks (e.g., 2012).; 30, comment:# Here we make sure the width is consistent over all years.; 31, for_statement; 32, comment:# Make the axes look good.; 33, expression_statement; 34, return_statement; 35, identifier:how; 36, string; 37, identifier:yearlabels; 38, True; 39, identifier:yearascending; 40, True; 41, identifier:yearlabel_kws; 42, None; 43, identifier:subplot_kws; 44, None; 45, identifier:gridspec_kws; 46, None; 47, identifier:fig_kws; 48, None; 49, identifier:kwargs; 50, comment:"""
      Plot a timeseries as a calendar heatmap.
  
      Parameters
      ----------
      data : Series
          Data for the plot. Must be indexed by a DatetimeIndex.
      how : string
          Method for resampling data by day. If `None`, assume data is already
          sampled by day and don't resample. Otherwise, this is passed to Pandas
          `Series.resample`.
      yearlabels : bool
         Whether or not to draw the year for each subplot.
      yearascending : bool
         Sort the calendar in ascending or descending order.
      yearlabel_kws : dict
         Keyword arguments passed to the matplotlib `set_ylabel` call which is
         used to draw the year for each subplot.
      subplot_kws : dict
          Keyword arguments passed to the matplotlib `add_subplot` call used to
          create each subplot.
      gridspec_kws : dict
          Keyword arguments passed to the matplotlib `GridSpec` constructor used
          to create the grid the subplots are placed on.
      fig_kws : dict
          Keyword arguments passed to the matplotlib `figure` call.
      kwargs : other keyword arguments
          All other keyword arguments are passed to `yearplot`.
  
      Returns
      -------
      fig, axes : matplotlib Figure and Axes
          Tuple where `fig` is the matplotlib Figure object `axes` is an array
          of matplotlib Axes objects with the calendar heatmaps, one per year.
  
      Examples
      --------
  
      With `calendarplot` we can plot several years in one figure:
  
      .. plot::
          :context: close-figs
  
          calmap.calendarplot(events)
  
      """; 51, assignment; 52, assignment; 53, assignment; 54, assignment; 55, assignment; 56, not_operator; 57, block; 58, assignment; 59, assignment; 60, comparison_operator:how is None; 61, block; 62, else_clause; 63, assignment; 64, call; 65, assignment; 66, pattern_list; 67, call; 68, block; 69, identifier:ax; 70, identifier:axes; 71, block; 72, call; 73, expression_list; 74, string_content:sum; 75, identifier:yearlabel_kws; 76, boolean_operator; 77, identifier:subplot_kws; 78, boolean_operator; 79, identifier:gridspec_kws; 80, boolean_operator; 81, identifier:fig_kws; 82, boolean_operator; 83, identifier:years; 84, call; 85, identifier:yearascending; 86, expression_statement; 87, pattern_list; 88, call; 89, identifier:axes; 90, subscript; 91, identifier:how; 92, None; 93, expression_statement; 94, block; 95, identifier:ylabel_kws; 96, call; 97, attribute; 98, argument_list; 99, identifier:max_weeks; 100, integer:0; 101, identifier:year; 102, identifier:ax; 103, identifier:zip; 104, argument_list; 105, expression_statement; 106, expression_statement; 107, if_statement; 108, expression_statement; 109, attribute; 110, argument_list; 111, identifier:fig; 112, identifier:axes; 113, identifier:yearlabel_kws; 114, dictionary; 115, identifier:subplot_kws; 116, dictionary; 117, identifier:gridspec_kws; 118, dictionary; 119, identifier:fig_kws; 120, dictionary; 121, attribute; 122, argument_list; 123, assignment; 124, identifier:fig; 125, identifier:axes; 126, attribute; 127, argument_list; 128, attribute; 129, integer:0; 130, assignment; 131, if_statement; 132, identifier:dict; 133, argument_list; 134, identifier:ylabel_kws; 135, identifier:update; 136, identifier:yearlabel_kws; 137, identifier:years; 138, identifier:axes; 139, call; 140, assignment; 141, identifier:yearlabels; 142, block; 143, call; 144, identifier:plt; 145, identifier:tight_layout; 146, identifier:np; 147, identifier:unique; 148, attribute; 149, identifier:years; 150, subscript; 151, identifier:plt; 152, identifier:subplots; 153, keyword_argument; 154, keyword_argument; 155, keyword_argument; 156, keyword_argument; 157, keyword_argument; 158, dictionary_splat; 159, identifier:axes; 160, identifier:T; 161, identifier:by_day; 162, identifier:data; 163, identifier:_pandas_18; 164, block; 165, else_clause; 166, keyword_argument; 167, keyword_argument; 168, keyword_argument; 169, keyword_argument; 170, keyword_argument; 171, identifier:yearplot; 172, argument_list; 173, identifier:max_weeks; 174, call; 175, expression_statement; 176, attribute; 177, argument_list; 178, attribute; 179, identifier:year; 180, identifier:years; 181, slice; 182, identifier:nrows; 183, call; 184, identifier:ncols; 185, integer:1; 186, identifier:squeeze; 187, False; 188, identifier:subplot_kw; 189, identifier:subplot_kws; 190, identifier:gridspec_kw; 191, identifier:gridspec_kws; 192, identifier:fig_kws; 193, expression_statement; 194, block; 195, identifier:fontsize; 196, integer:32; 197, identifier:color; 198, call; 199, identifier:fontweight; 200, string; 201, identifier:fontname; 202, string; 203, identifier:ha; 204, string; 205, identifier:by_day; 206, keyword_argument; 207, keyword_argument; 208, keyword_argument; 209, dictionary_splat; 210, identifier:max; 211, argument_list; 212, call; 213, identifier:ax; 214, identifier:set_xlim; 215, integer:0; 216, identifier:max_weeks; 217, identifier:data; 218, identifier:index; 219, unary_operator; 220, identifier:len; 221, argument_list; 222, assignment; 223, expression_statement; 224, attribute; 225, argument_list; 226, string_content:bold; 227, string_content:Arial; 228, string_content:center; 229, identifier:year; 230, identifier:year; 231, identifier:how; 232, None; 233, identifier:ax; 234, identifier:ax; 235, identifier:kwargs; 236, identifier:max_weeks; 237, subscript; 238, attribute; 239, argument_list; 240, integer:1; 241, identifier:years; 242, identifier:by_day; 243, call; 244, assignment; 245, identifier:kwargs; 246, identifier:get; 247, string; 248, string; 249, call; 250, integer:1; 251, identifier:ax; 252, identifier:set_ylabel; 253, call; 254, dictionary_splat; 255, attribute; 256, argument_list; 257, identifier:by_day; 258, call; 259, string_content:fillcolor; 260, string_content:whitesmoke; 261, attribute; 262, argument_list; 263, identifier:str; 264, argument_list; 265, identifier:ylabel_kws; 266, call; 267, identifier:agg; 268, identifier:how; 269, attribute; 270, argument_list; 271, identifier:ax; 272, identifier:get_xlim; 273, identifier:year; 274, attribute; 275, argument_list; 276, identifier:data; 277, identifier:resample; 278, string; 279, keyword_argument; 280, identifier:data; 281, identifier:resample; 282, string; 283, string_content:D; 284, identifier:how; 285, identifier:how; 286, string_content:D
code: def calendarplot(data, how='sum', yearlabels=True, yearascending=True, yearlabel_kws=None,
                   subplot_kws=None, gridspec_kws=None, fig_kws=None, **kwargs):
      """
      Plot a timeseries as a calendar heatmap.
  
      Parameters
      ----------
      data : Series
          Data for the plot. Must be indexed by a DatetimeIndex.
      how : string
          Method for resampling data by day. If `None`, assume data is already
          sampled by day and don't resample. Otherwise, this is passed to Pandas
          `Series.resample`.
      yearlabels : bool
         Whether or not to draw the year for each subplot.
      yearascending : bool
         Sort the calendar in ascending or descending order.
      yearlabel_kws : dict
         Keyword arguments passed to the matplotlib `set_ylabel` call which is
         used to draw the year for each subplot.
      subplot_kws : dict
          Keyword arguments passed to the matplotlib `add_subplot` call used to
          create each subplot.
      gridspec_kws : dict
          Keyword arguments passed to the matplotlib `GridSpec` constructor used
          to create the grid the subplots are placed on.
      fig_kws : dict
          Keyword arguments passed to the matplotlib `figure` call.
      kwargs : other keyword arguments
          All other keyword arguments are passed to `yearplot`.
  
      Returns
      -------
      fig, axes : matplotlib Figure and Axes
          Tuple where `fig` is the matplotlib Figure object `axes` is an array
          of matplotlib Axes objects with the calendar heatmaps, one per year.
  
      Examples
      --------
  
      With `calendarplot` we can plot several years in one figure:
  
      .. plot::
          :context: close-figs
  
          calmap.calendarplot(events)
  
      """
      yearlabel_kws = yearlabel_kws or {}
      subplot_kws = subplot_kws or {}
      gridspec_kws = gridspec_kws or {}
      fig_kws = fig_kws or {}
  
      years = np.unique(data.index.year)
      if not yearascending:
          years = years[::-1]
  
      fig, axes = plt.subplots(nrows=len(years), ncols=1, squeeze=False,
                               subplot_kw=subplot_kws,
                               gridspec_kw=gridspec_kws, **fig_kws)
      axes = axes.T[0]
  
      # We explicitely resample by day only once. This is an optimization.
      if how is None:
          by_day = data
      else:
          if _pandas_18:
              by_day = data.resample('D').agg(how)
          else:
              by_day = data.resample('D', how=how)
  
      ylabel_kws = dict(
          fontsize=32,
          color=kwargs.get('fillcolor', 'whitesmoke'),
          fontweight='bold',
          fontname='Arial',
          ha='center')
      ylabel_kws.update(yearlabel_kws)
  
      max_weeks = 0
  
      for year, ax in zip(years, axes):
          yearplot(by_day, year=year, how=None, ax=ax, **kwargs)
          max_weeks = max(max_weeks, ax.get_xlim()[1])
  
          if yearlabels:
              ax.set_ylabel(str(year), **ylabel_kws)
  
      # In a leap year it might happen that we have 54 weeks (e.g., 2012).
      # Here we make sure the width is consistent over all years.
      for ax in axes:
          ax.set_xlim(0, max_weeks)
  
      # Make the axes look good.
      plt.tight_layout()
  
      return fig, axes