def plot_z_phase_calibration_result(
    before_after_df: pd.DataFrame,
    axes: np.ndarray[tuple[int, int], np.dtype[np.object_]] | None = None,
    pairs: Sequence[tuple[cirq.Qid, cirq.Qid]] | None = None,
    *,
    with_error_bars: bool = False,
) -> np.ndarray[tuple[int, int], np.dtype[np.object_]]:
    """A helper method to plot the result of running z-phase calibration.

    Note that the plotted fidelity is a statistical estimate of the true fidelity and as a result
    may be outside the [0, 1] range.

    Args:
        before_after_df: The second return object of running `z_phase_calibration_workflow`.
        axes: And ndarray of the axes to plot on.
            The number of axes is expected to be >= number of qubit pairs.
        pairs: If provided, only the given pairs are plotted.
        with_error_bars: Whether to add error bars or not.
            The width of the bar is an upper bound on standard variation of the estimated fidelity.
    """
    if pairs is None:
        pairs = before_after_df.index
    if axes is None:
        # Create a 16x9 rectangle.
        ncols = int(np.ceil(np.sqrt(9 / 16 * len(pairs))))
        nrows = (len(pairs) + ncols - 1) // ncols
        _, axes = plt.subplots(nrows=nrows, ncols=ncols)
    axes = axes if isinstance(axes, np.ndarray) else np.array(axes)
    for pair, ax in zip(pairs, axes.flatten()):
        row = before_after_df.loc[[pair]].iloc[0]
        ax.errorbar(
            row.cycle_depths_0,
            row.fidelities_0,
            yerr=row.layer_fid_std_0 * with_error_bars,
            label='original',
        )
        ax.errorbar(
            row.cycle_depths_0,
            row.fidelities_c,
            yerr=row.layer_fid_std_c * with_error_bars,
            label='calibrated',
        )
        ax.axhline(1, linestyle='--')
        ax.set_xlabel('cycle depth')
        ax.set_ylabel('fidelity estimate')
        ax.set_title('-'.join(str(q) for q in pair))
        ax.legend()
    return axes
A helper method to plot the result of running z-phase calibration.

    Note that the plotted fidelity is a statistical estimate of the true fidelity and as a result
    may be outside the [0, 1] range.

    Args:
        before_after_df: The second return object of running `z_phase_calibration_workflow`.
        axes: And ndarray of the axes to plot on.
            The number of axes is expected to be >= number of qubit pairs.
        pairs: If provided, only the given pairs are plotted.
        with_error_bars: Whether to add error bars or not.
            The width of the bar is an upper bound on standard variation of the estimated fidelity.
    
cirq-core/cirq/experiments/z_phase_calibration.py