code: def segments(intervals, labels, base=None, height=None, text=False,
               text_kw=None, ax=None, **kwargs):
      '''Plot a segmentation as a set of disjoint rectangles.
      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`.
      base : number
          The vertical position of the base of the rectangles.
          By default, this will be the bottom of the plot.
      height : number
          The height of the rectangles.
          By default, this will be the top of the plot (minus ``base``).
      text : bool
          If true, each segment's label is displayed in its
          upper-left corner
      text_kw : dict
          If ``text == True``, the properties of the text
          object can be specified here.
          See ``matplotlib.pyplot.Text`` for valid parameters
      ax : matplotlib.pyplot.axes
          An axis handle on which to draw the segmentation.
          If none is provided, a new set of axes is created.
      kwargs
          Additional keyword arguments to pass to
          ``matplotlib.patches.Rectangle``.
      Returns
      -------
      ax : matplotlib.pyplot.axes._subplots.AxesSubplot
          A handle to the (possibly constructed) plot axes
      '''
      if text_kw is None:
          text_kw = dict()
      text_kw.setdefault('va', 'top')
      text_kw.setdefault('clip_on', True)
      text_kw.setdefault('bbox', dict(boxstyle='round', facecolor='white'))
      intervals = np.atleast_2d(intervals)
      seg_def_style = dict(linewidth=1)
      ax, new_axes = __get_axes(ax=ax)
      if new_axes:
          ax.set_ylim([0, 1])
      if base is None:
          base = ax.get_ylim()[0]
      if height is None:
          height = ax.get_ylim()[1]
      cycler = ax._get_patches_for_fill.prop_cycler
      seg_map = dict()
      for lab in labels:
          if lab in seg_map:
              continue
          style = next(cycler)
          seg_map[lab] = seg_def_style.copy()
          seg_map[lab].update(style)
          seg_map[lab]['facecolor'] = seg_map[lab].pop('color')
          seg_map[lab].update(kwargs)
          seg_map[lab]['label'] = lab
      for ival, lab in zip(intervals, labels):
          rect = Rectangle((ival[0], base), ival[1] - ival[0], height,
                           **seg_map[lab])
          ax.add_patch(rect)
          seg_map[lab].pop('label', None)
          if text:
              ann = ax.annotate(lab,
                                xy=(ival[0], height), xycoords='data',
                                xytext=(8, -10), textcoords='offset points',
                                **text_kw)
              ann.set_clip_path(rect)
      if new_axes:
          ax.set_yticks([])
      if intervals.size:
          __expand_limits(ax, [intervals.min(), intervals.max()], which='x')
      return ax