def plot_state_histogram(
    data: result.Result | collections.Counter | Sequence[SupportsFloat],
    ax: plt.Axes | None = None,
    *,
    tick_label: Sequence[str] | None = None,
    xlabel: str | None = 'qubit state',
    ylabel: str | None = 'result count',
    title: str | None = 'Result State Histogram',
) -> plt.Axes:
    """Plot the state histogram from either a single result with repetitions or
       a histogram computed using `result.histogram()` or a flattened histogram
       of measurement results computed using `get_state_histogram`.

    Args:
        data:   The histogram values to plot. Possible options are:
                `result.Result`: Histogram is computed using
                    `get_state_histogram` and all 2 ** num_qubits values are
                    plotted, including 0s.
                `collections.Counter`: Only (key, value) pairs present in
                    collection are plotted.
                `Sequence[SupportsFloat]`: Values in the input sequence are
                    plotted. i'th entry corresponds to height of the i'th
                    bar in histogram.
        ax:      The Axes to plot on. If not given, a new figure is created,
                 plotted on, and shown.
        tick_label: Tick labels for the histogram plot in case input is not
                    `collections.Counter`. By default, label for i'th entry
                     is |i>.
        xlabel:  Label for the x-axis.
        ylabel:  Label for the y-axis.
        title:   Title of the plot.

    Returns:
        The axis that was plotted on.
    """
    show_fig = not ax
    if ax is None:
        fig, ax = plt.subplots(1, 1)
    if isinstance(data, result.Result):
        values = get_state_histogram(data)
    elif isinstance(data, collections.Counter):
        tick_label, counts = zip(*sorted(data.items()))
        values = np.asarray(counts)
    else:
        values = np.array(data)
    if tick_label is None:
        tick_label = [str(i) for i in range(len(values))]
    ax.bar(np.arange(len(values)), values, tick_label=tick_label)
    if xlabel:
        ax.set_xlabel(xlabel)
    if ylabel:
        ax.set_ylabel(ylabel)
    if title:
        ax.set_title(title)
    if show_fig:
        fig.show()
    return ax
Plot the state histogram from either a single result with repetitions or
       a histogram computed using `result.histogram()` or a flattened histogram
       of measurement results computed using `get_state_histogram`.

    Args:
        data:   The histogram values to plot. Possible options are:
                `result.Result`: Histogram is computed using
                    `get_state_histogram` and all 2 ** num_qubits values are
                    plotted, including 0s.
                `collections.Counter`: Only (key, value) pairs present in
                    collection are plotted.
                `Sequence[SupportsFloat]`: Values in the input sequence are
                    plotted. i'th entry corresponds to height of the i'th
                    bar in histogram.
        ax:      The Axes to plot on. If not given, a new figure is created,
                 plotted on, and shown.
        tick_label: Tick labels for the histogram plot in case input is not
                    `collections.Counter`. By default, label for i'th entry
                     is |i>.
        xlabel:  Label for the x-axis.
        ylabel:  Label for the y-axis.
        title:   Title of the plot.

    Returns:
        The axis that was plotted on.
    
cirq-core/cirq/vis/state_histogram.py