nodes: 0, module; 1, function_definition; 2, function_name:labeled_intervals; 3, parameters; 4, block; 5, identifier:intervals; 6, identifier:labels; 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, comment:# Get the axes handle; 16, expression_statement; 17, comment:# Make sure we have a numpy array; 18, expression_statement; 19, if_statement; 20, comment:# Put additional labels at the end, in order; 21, if_statement; 22, expression_statement; 23, expression_statement; 24, comment:# Swap color -> facecolor here so we preserve edgecolor on rects; 25, expression_statement; 26, expression_statement; 27, if_statement; 28, if_statement; 29, if_statement; 30, expression_statement; 31, for_statement; 32, expression_statement; 33, for_statement; 34, for_statement; 35, comment:# Draw a line separating the new labels from pre-existing labels; 36, if_statement; 37, if_statement; 38, if_statement; 39, if_statement; 40, return_statement; 41, identifier:label_set; 42, None; 43, identifier:base; 44, None; 45, identifier:height; 46, None; 47, identifier:extend_labels; 48, True; 49, identifier:ax; 50, None; 51, identifier:tick; 52, True; 53, identifier:kwargs; 54, string; 55, assignment; 56, assignment; 57, comparison_operator:label_set is None; 58, comment:# If we have non-empty pre-existing tick labels, use them; 59, block; 60, else_clause; 61, identifier:extend_labels; 62, block; 63, elif_clause; 64, else_clause; 65, assignment; 66, call; 67, assignment; 68, call; 69, comparison_operator:base is None; 70, block; 71, comparison_operator:height is None; 72, block; 73, call; 74, block; 75, assignment; 76, pattern_list; 77, call; 78, block; 79, assignment; 80, pattern_list; 81, call; 82, block; 83, identifier:lab; 84, identifier:seg_y; 85, block; 86, comparison_operator:label_set != ticks; 87, block; 88, identifier:tick; 89, block; 90, attribute; 91, block; 92, attribute; 93, block; 94, identifier:ax; 95, string_content:Plot labeled intervals with each label on its own row.
  
      Parameters
      ----------
      intervals : np.ndarray, shape=(n, 2)
          segment intervals, in the format returned by
          :func:`mir_eval.io.load_intervals` or
          :func:`mir_eval.io.load_labeled_intervals`.
  
      labels : list, shape=(n,)
          reference segment labels, in the format returned by
          :func:`mir_eval.io.load_labeled_intervals`.
  
      label_set : list
          An (ordered) list of labels to determine the plotting order.
          If not provided, the labels will be inferred from
          ``ax.get_yticklabels()``.
          If no ``yticklabels`` exist, then the sorted set of unique values
          in ``labels`` is taken as the label set.
  
      base : np.ndarray, shape=(n,), optional
          Vertical positions of each label.
          By default, labels are positioned at integers
          ``np.arange(len(labels))``.
  
      height : scalar or np.ndarray, shape=(n,), optional
          Height for each label.
          If scalar, the same value is applied to all labels.
          By default, each label has ``height=1``.
  
      extend_labels : bool
          If ``False``, only values of ``labels`` that also exist in
          ``label_set`` will be shown.
  
          If ``True``, all labels are shown, with those in `labels` but
          not in `label_set` appended to the top of the plot.
          A horizontal line is drawn to indicate the separation between
          values in or out of ``label_set``.
  
      ax : matplotlib.pyplot.axes
          An axis handle on which to draw the intervals.
          If none is provided, a new set of axes is created.
  
      tick : bool
          If ``True``, sets tick positions and labels on the y-axis.
  
      kwargs
          Additional keyword arguments to pass to
          `matplotlib.collection.BrokenBarHCollection`.
  
      Returns
      -------
      ax : matplotlib.pyplot.axes._subplots.AxesSubplot
          A handle to the (possibly constructed) plot axes; 96, pattern_list; 97, call; 98, identifier:intervals; 99, call; 100, identifier:label_set; 101, None; 102, expression_statement; 103, comment:# If none of the label strings have content, treat it as empty; 104, if_statement; 105, block; 106, expression_statement; 107, identifier:label_set; 108, block; 109, block; 110, identifier:style; 111, call; 112, attribute; 113, argument_list; 114, subscript; 115, call; 116, attribute; 117, argument_list; 118, identifier:base; 119, None; 120, expression_statement; 121, identifier:height; 122, None; 123, expression_statement; 124, attribute; 125, argument_list; 126, expression_statement; 127, identifier:seg_y; 128, call; 129, identifier:ybase; 130, identifier:yheight; 131, identifier:lab; 132, identifier:zip; 133, argument_list; 134, expression_statement; 135, identifier:xvals; 136, call; 137, identifier:ival; 138, identifier:lab; 139, identifier:zip; 140, argument_list; 141, if_statement; 142, expression_statement; 143, expression_statement; 144, comment:# Pop the label after the first time we see it, so we only get; 145, comment:# one legend entry; 146, expression_statement; 147, identifier:label_set; 148, identifier:ticks; 149, expression_statement; 150, expression_statement; 151, expression_statement; 152, expression_statement; 153, expression_statement; 154, expression_statement; 155, identifier:base; 156, identifier:size; 157, expression_statement; 158, identifier:intervals; 159, identifier:size; 160, expression_statement; 161, identifier:ax; 162, identifier:_; 163, identifier:__get_axes; 164, argument_list; 165, attribute; 166, argument_list; 167, assignment; 168, not_operator; 169, block; 170, expression_statement; 171, assignment; 172, expression_statement; 173, expression_statement; 174, identifier:dict; 175, argument_list; 176, identifier:style; 177, identifier:update; 178, call; 179, identifier:style; 180, string; 181, attribute; 182, argument_list; 183, identifier:style; 184, identifier:update; 185, identifier:kwargs; 186, assignment; 187, assignment; 188, identifier:np; 189, identifier:isscalar; 190, identifier:height; 191, assignment; 192, identifier:dict; 193, argument_list; 194, identifier:base; 195, identifier:height; 196, identifier:ticks; 197, assignment; 198, identifier:defaultdict; 199, argument_list; 200, identifier:intervals; 201, identifier:labels; 202, comparison_operator:lab not in seg_y; 203, block; 204, call; 205, call; 206, call; 207, call; 208, call; 209, call; 210, call; 211, call; 212, call; 213, call; 214, call; 215, keyword_argument; 216, identifier:np; 217, identifier:atleast_2d; 218, identifier:intervals; 219, identifier:label_set; 220, list_comprehension; 221, call; 222, expression_statement; 223, assignment; 224, identifier:ticks; 225, binary_operator:label_set + sorted(set(labels) - set(label_set)); 226, assignment; 227, assignment; 228, keyword_argument; 229, identifier:next; 230, argument_list; 231, string_content:facecolor; 232, identifier:style; 233, identifier:pop; 234, string; 235, identifier:base; 236, call; 237, identifier:height; 238, integer:1; 239, identifier:height; 240, binary_operator:height * np.ones_like(base); 241, subscript; 242, tuple; 243, identifier:list; 244, identifier:lab; 245, identifier:seg_y; 246, continue_statement; 247, attribute; 248, argument_list; 249, attribute; 250, argument_list; 251, attribute; 252, argument_list; 253, attribute; 254, argument_list; 255, attribute; 256, argument_list; 257, attribute; 258, argument_list; 259, attribute; 260, argument_list; 261, attribute; 262, argument_list; 263, attribute; 264, argument_list; 265, identifier:__expand_limits; 266, argument_list; 267, identifier:__expand_limits; 268, argument_list; 269, identifier:ax; 270, identifier:ax; 271, call; 272, for_in_clause; 273, identifier:any; 274, argument_list; 275, assignment; 276, identifier:label_set; 277, call; 278, identifier:label_set; 279, call; 280, identifier:ticks; 281, identifier:label_set; 282, identifier:ticks; 283, call; 284, identifier:linewidth; 285, integer:1; 286, attribute; 287, string_content:color; 288, attribute; 289, argument_list; 290, identifier:height; 291, call; 292, identifier:seg_y; 293, identifier:lab; 294, identifier:ybase; 295, identifier:yheight; 296, subscript; 297, identifier:append; 298, tuple; 299, identifier:ax; 300, identifier:add_collection; 301, call; 302, identifier:style; 303, identifier:pop; 304, string; 305, None; 306, identifier:ax; 307, identifier:axhline; 308, call; 309, keyword_argument; 310, keyword_argument; 311, identifier:ax; 312, identifier:grid; 313, True; 314, keyword_argument; 315, identifier:ax; 316, identifier:set_yticks; 317, list; 318, identifier:ax; 319, identifier:set_yticks; 320, identifier:base; 321, identifier:ax; 322, identifier:set_yticklabels; 323, identifier:ticks; 324, keyword_argument; 325, attribute; 326, identifier:set_major_formatter; 327, call; 328, identifier:ax; 329, list; 330, keyword_argument; 331, identifier:ax; 332, list; 333, keyword_argument; 334, attribute; 335, argument_list; 336, identifier:_; 337, call; 338, identifier:label_set; 339, identifier:label_set; 340, list; 341, identifier:list; 342, argument_list; 343, identifier:sorted; 344, argument_list; 345, identifier:sorted; 346, argument_list; 347, attribute; 348, identifier:prop_cycler; 349, identifier:np; 350, identifier:arange; 351, call; 352, attribute; 353, argument_list; 354, identifier:xvals; 355, identifier:lab; 356, subscript; 357, binary_operator:ival[1] - ival[0]; 358, identifier:BrokenBarHCollection; 359, argument_list; 360, string_content:label; 361, identifier:len; 362, argument_list; 363, identifier:color; 364, string; 365, identifier:alpha; 366, float:0.5; 367, identifier:axis; 368, string; 369, identifier:va; 370, string; 371, identifier:ax; 372, identifier:yaxis; 373, identifier:IntervalFormatter; 374, argument_list; 375, call; 376, call; 377, identifier:which; 378, string; 379, call; 380, call; 381, identifier:which; 382, string; 383, identifier:_; 384, identifier:get_text; 385, attribute; 386, argument_list; 387, identifier:label_set; 388, binary_operator:set(labels) - set(label_set); 389, call; 390, identifier:ax; 391, identifier:_get_patches_for_fill; 392, identifier:len; 393, argument_list; 394, identifier:np; 395, identifier:ones_like; 396, identifier:base; 397, identifier:ival; 398, integer:0; 399, subscript; 400, subscript; 401, subscript; 402, subscript; 403, dictionary_splat; 404, identifier:label_set; 405, string_content:k; 406, string_content:y; 407, string_content:bottom; 408, identifier:base; 409, identifier:ticks; 410, attribute; 411, argument_list; 412, attribute; 413, argument_list; 414, string_content:y; 415, attribute; 416, argument_list; 417, attribute; 418, argument_list; 419, string_content:x; 420, identifier:ax; 421, identifier:get_yticklabels; 422, call; 423, call; 424, identifier:set; 425, argument_list; 426, identifier:ticks; 427, identifier:ival; 428, integer:1; 429, identifier:ival; 430, integer:0; 431, identifier:xvals; 432, identifier:lab; 433, identifier:seg_y; 434, identifier:lab; 435, identifier:style; 436, identifier:base; 437, identifier:min; 438, parenthesized_expression; 439, identifier:max; 440, identifier:intervals; 441, identifier:min; 442, identifier:intervals; 443, identifier:max; 444, identifier:set; 445, argument_list; 446, identifier:set; 447, argument_list; 448, identifier:labels; 449, binary_operator:base + height; 450, identifier:labels; 451, identifier:label_set; 452, identifier:base; 453, identifier:height
code: def labeled_intervals(intervals, labels, label_set=None,
                        base=None, height=None, extend_labels=True,
                        ax=None, tick=True, **kwargs):
      '''Plot labeled intervals with each label on its own row.
  
      Parameters
      ----------
      intervals : np.ndarray, shape=(n, 2)
          segment intervals, in the format returned by
          :func:`mir_eval.io.load_intervals` or
          :func:`mir_eval.io.load_labeled_intervals`.
  
      labels : list, shape=(n,)
          reference segment labels, in the format returned by
          :func:`mir_eval.io.load_labeled_intervals`.
  
      label_set : list
          An (ordered) list of labels to determine the plotting order.
          If not provided, the labels will be inferred from
          ``ax.get_yticklabels()``.
          If no ``yticklabels`` exist, then the sorted set of unique values
          in ``labels`` is taken as the label set.
  
      base : np.ndarray, shape=(n,), optional
          Vertical positions of each label.
          By default, labels are positioned at integers
          ``np.arange(len(labels))``.
  
      height : scalar or np.ndarray, shape=(n,), optional
          Height for each label.
          If scalar, the same value is applied to all labels.
          By default, each label has ``height=1``.
  
      extend_labels : bool
          If ``False``, only values of ``labels`` that also exist in
          ``label_set`` will be shown.
  
          If ``True``, all labels are shown, with those in `labels` but
          not in `label_set` appended to the top of the plot.
          A horizontal line is drawn to indicate the separation between
          values in or out of ``label_set``.
  
      ax : matplotlib.pyplot.axes
          An axis handle on which to draw the intervals.
          If none is provided, a new set of axes is created.
  
      tick : bool
          If ``True``, sets tick positions and labels on the y-axis.
  
      kwargs
          Additional keyword arguments to pass to
          `matplotlib.collection.BrokenBarHCollection`.
  
      Returns
      -------
      ax : matplotlib.pyplot.axes._subplots.AxesSubplot
          A handle to the (possibly constructed) plot axes
      '''
  
      # Get the axes handle
      ax, _ = __get_axes(ax=ax)
  
      # Make sure we have a numpy array
      intervals = np.atleast_2d(intervals)
  
      if label_set is None:
          # If we have non-empty pre-existing tick labels, use them
          label_set = [_.get_text() for _ in ax.get_yticklabels()]
          # If none of the label strings have content, treat it as empty
          if not any(label_set):
              label_set = []
      else:
          label_set = list(label_set)
  
      # Put additional labels at the end, in order
      if extend_labels:
          ticks = label_set + sorted(set(labels) - set(label_set))
      elif label_set:
          ticks = label_set
      else:
          ticks = sorted(set(labels))
  
      style = dict(linewidth=1)
  
      style.update(next(ax._get_patches_for_fill.prop_cycler))
      # Swap color -> facecolor here so we preserve edgecolor on rects
      style['facecolor'] = style.pop('color')
      style.update(kwargs)
  
      if base is None:
          base = np.arange(len(ticks))
  
      if height is None:
          height = 1
  
      if np.isscalar(height):
          height = height * np.ones_like(base)
  
      seg_y = dict()
      for ybase, yheight, lab in zip(base, height, ticks):
          seg_y[lab] = (ybase, yheight)
  
      xvals = defaultdict(list)
      for ival, lab in zip(intervals, labels):
          if lab not in seg_y:
              continue
          xvals[lab].append((ival[0], ival[1] - ival[0]))
  
      for lab in seg_y:
          ax.add_collection(BrokenBarHCollection(xvals[lab], seg_y[lab],
                                                 **style))
          # Pop the label after the first time we see it, so we only get
          # one legend entry
          style.pop('label', None)
  
      # Draw a line separating the new labels from pre-existing labels
      if label_set != ticks:
          ax.axhline(len(label_set), color='k', alpha=0.5)
  
      if tick:
          ax.grid(True, axis='y')
          ax.set_yticks([])
          ax.set_yticks(base)
          ax.set_yticklabels(ticks, va='bottom')
          ax.yaxis.set_major_formatter(IntervalFormatter(base, ticks))
  
      if base.size:
          __expand_limits(ax, [base.min(), (base + height).max()], which='y')
      if intervals.size:
          __expand_limits(ax, [intervals.min(), intervals.max()], which='x')
  
      return ax