# mir_eval.display

Display functions

mir_eval.display.segments(intervals, labels, base=None, height=None, text=False, text_kw=None, ax=None, prop_cycle=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 `mir_eval.io.load_intervals()` or `mir_eval.io.load_labeled_intervals()`.

    labels list, shape=(n,)

      reference segment labels, in the format returned by `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`). .. note:: If either base or height are provided, both must be provided.

    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.

    prop_cycle cycle.Cycler

      An optional property cycle object to specify style properties. If not provided, the default property cycler will be retrieved from matplotlib.

    **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

mir_eval.display.labeled_intervals(intervals, labels, label_set=None, base=None, height=None, extend_labels=True, ax=None, tick=True, prop_cycle=None, **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 `mir_eval.io.load_intervals()` or `mir_eval.io.load_labeled_intervals()`.

    labels list, shape=(n,)

      reference segment labels, in the format returned by `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.

    prop_cycle cycle.Cycler

      An optional property cycle object to specify style properties. If not provided, the default property cycler will be retrieved from matplotlib.

    **kwargs

      Additional keyword arguments to pass to matplotlib.collection.PolyCollection.

  Returns:
    ax matplotlib.pyplot.axes._subplots.AxesSubplot

      A handle to the (possibly constructed) plot axes

class mir_eval.display.IntervalFormatter(base, ticks)

  Bases: `Formatter`

  Ticker formatter for labeled interval plots.

  Parameters:
    base array-like of int

      The base positions of each label

    ticks array-like of string

      The labels for the ticks

  Attributes:
    axis

  Methods

  `__call__`(x[, pos]) | Map the input position to its corresponding interval label
  `fix_minus`(s) | Some classes may want to replace a hyphen for minus with the proper Unicode symbol (U+2212) for typographical correctness. This is a helper method to perform such a replacement when it is enabled via :rc:`axes.unicode_minus`.
  `format_data`(value) | Return the full string representation of the value with the position unspecified.
  `format_data_short`(value) | Return a short string version of the tick value.
  `format_ticks`(values) | Return the tick labels for all the ticks at once.
  `set_locs`(locs) | Set the locations of the ticks.

  create_dummy_axis |
  get_offset |
  set_axis |

mir_eval.display.hierarchy(intervals_hier, labels_hier, levels=None, ax=None, **kwargs)

  Plot a hierarchical segmentation

  Parameters:
    intervals_hier list of np.ndarray

      A list of segmentation intervals. Each element should be an n-by-2 array of segment intervals, in the format returned by `mir_eval.io.load_intervals()` or `mir_eval.io.load_labeled_intervals()`. Segmentations should be ordered by increasing specificity.

    labels_hier list of list-like

      A list of segmentation labels. Each element should be a list of labels for the corresponding element in intervals_hier.

    levels list of string

      Each element `levels[i]` is a label for the ``i` th segmentation. This is used in the legend to denote the levels in a segment hierarchy.

    ax matplotlib.pyplot.axes

      An axis handle on which to draw the intervals. If none is provided, a new set of axes is created.

    **kwargs

      Additional keyword arguments to labeled_intervals.

  Returns:
    ax matplotlib.pyplot.axes._subplots.AxesSubplot

      A handle to the (possibly constructed) plot axes

mir_eval.display.events(times, labels=None, base=None, height=None, ax=None, text_kw=None, prop_cycle=None, **kwargs)

  Plot event times as a set of vertical lines

  Parameters:
    times np.ndarray, shape=(n,)

      event times, in the format returned by `mir_eval.io.load_events()` or `mir_eval.io.load_labeled_events()`.

    labels list, shape=(n,), optional

      event labels, in the format returned by `mir_eval.io.load_labeled_events()`.

    base number

      The vertical position of the base of the line. By default, this will be the bottom of the plot.

    height number

      The height of the lines. By default, this will be the top of the plot (minus base). .. note:: If either base or height are provided, both must be provided.

    ax matplotlib.pyplot.axes

      An axis handle on which to draw the segmentation. If none is provided, a new set of axes is created.

    text_kw dict

      If labels is provided, the properties of the text objects can be specified here. See matplotlib.pyplot.Text for valid parameters

    prop_cycle cycle.Cycler

      An optional property cycle object to specify style properties. If not provided, the default property cycler will be retrieved from matplotlib.

    **kwargs

      Additional keyword arguments to pass to matplotlib.pyplot.vlines.

  Returns:
    ax matplotlib.pyplot.axes._subplots.AxesSubplot

      A handle to the (possibly constructed) plot axes

mir_eval.display.pitch(times, frequencies, midi=False, unvoiced=False, ax=None, prop_cycle=None, **kwargs)

  Visualize pitch contours

  Parameters:
    times np.ndarray, shape=(n,)

      Sample times of frequencies

    frequencies np.ndarray, shape=(n,)

      frequencies (in Hz) of the pitch contours. Voicing is indicated by sign (positive for voiced, non-positive for non-voiced).

    midi bool

      If True, plot on a MIDI-numbered vertical axis. Otherwise, plot on a linear frequency axis.

    unvoiced bool

      If True, unvoiced pitch contours are plotted and indicated by transparency.

      Otherwise, unvoiced pitch contours are omitted from the display.

    ax matplotlib.pyplot.axes

      An axis handle on which to draw the pitch contours. If none is provided, a new set of axes is created.

    prop_cycle cycle.Cycler

      An optional property cycle object to specify style properties. If not provided, the default property cycler will be retrieved from matplotlib.

    **kwargs

      Additional keyword arguments to matplotlib.pyplot.plot.

  Returns:
    ax matplotlib.pyplot.axes._subplots.AxesSubplot

      A handle to the (possibly constructed) plot axes

mir_eval.display.multipitch(times, frequencies, midi=False, unvoiced=False, ax=None, prop_cycle=None, **kwargs)

  Visualize multiple f0 measurements

  Parameters:
    times np.ndarray, shape=(n,)

      Sample times of frequencies

    frequencies list of np.ndarray

      frequencies (in Hz) of the pitch measurements. Voicing is indicated by sign (positive for voiced, non-positive for non-voiced).

      times and frequencies should be in the format produced by `mir_eval.io.load_ragged_time_series()`

    midi bool

      If True, plot on a MIDI-numbered vertical axis. Otherwise, plot on a linear frequency axis.

    unvoiced bool

      If True, unvoiced pitches are plotted and indicated by transparency.

      Otherwise, unvoiced pitches are omitted from the display.

    ax matplotlib.pyplot.axes

      An axis handle on which to draw the pitch contours. If none is provided, a new set of axes is created.

    prop_cycle cycle.Cycler

      An optional property cycle object to specify style properties. If not provided, the default property cycler will be retrieved from matplotlib.

    **kwargs

      Additional keyword arguments to plt.scatter.

  Returns:
    ax matplotlib.pyplot.axes._subplots.AxesSubplot

      A handle to the (possibly constructed) plot axes

mir_eval.display.piano_roll(intervals, pitches=None, midi=None, ax=None, **kwargs)

  Plot a quantized piano roll as intervals

  Parameters:
    intervals np.ndarray, shape=(n, 2)

      timing intervals for notes

    pitches np.ndarray, shape=(n,), optional

      pitches of notes (in Hz).

    midi np.ndarray, shape=(n,), optional

      pitches of notes (in MIDI numbers).

      At least one of `pitches` or `midi` must be provided.

    ax matplotlib.pyplot.axes

      An axis handle on which to draw the intervals. If none is provided, a new set of axes is created.

    **kwargs

      Additional keyword arguments to `labeled_intervals()`.

  Returns:
    ax matplotlib.pyplot.axes._subplots.AxesSubplot

      A handle to the (possibly constructed) plot axes

mir_eval.display.separation(sources, fs=22050, labels=None, alpha=0.75, ax=None, rasterized=True, edgecolors='None', shading='gouraud', prop_cycle=None, **kwargs)

  Source-separation visualization

  Parameters:
    sources np.ndarray, shape=(nsrc, nsampl)

      A list of waveform buffers corresponding to each source

    fs number > 0

      The sampling rate

    labels list of strings

      An optional list of descriptors corresponding to each source

    alpha float in [0, 1]

      Maximum alpha (opacity) of spectrogram values.

    ax matplotlib.pyplot.axes

      An axis handle on which to draw the spectrograms. If none is provided, a new set of axes is created.

    rasterized bool

      If True, the spectrogram is rasterized.

    edgecolors str or None

      The color of the edges of the spectrogram patches. Set to “None” (default) to disable edge coloring.

    shading str

      The shading method to use for the spectrogram. See matplotlib.pyplot.pcolormesh for valid options.

    prop_cycle cycle.Cycler

      An optional property cycle object to specify colors for each signal. If not provided, the default property cycler will be retrieved from matplotlib.

    **kwargs

      Additional keyword arguments to `scipy.signal.spectrogram`

  Returns:
    ax

      The axis handle for this plot

mir_eval.display.ticker_notes(ax=None)

  Set the y-axis of the given axes to MIDI notes

  Parameters:
    ax matplotlib.pyplot.axes

      The axes handle to apply the ticker. By default, uses the current axes handle.

mir_eval.display.ticker_pitch(ax=None)

  Set the y-axis of the given axes to MIDI frequencies

  Parameters:
    ax matplotlib.pyplot.axes

      The axes handle to apply the ticker. By default, uses the current axes handle.