def plot_error_map(backend, figsize=(12, 9), show_title=True):
    "Plots the error map of a given backend.\n\n    Args:\n        backend (IBMQBackend): Given backend.\n        figsize (tuple): Figure size in inches.\n        show_title (bool): Show the title or not.\n\n    Returns:\n        Figure: A matplotlib figure showing error map.\n\n    Raises:\n        VisualizationError: Input is not IBMQ backend.\n        ImportError: If seaborn is not installed\n\n    Example:\n        .. jupyter-execute::\n            :hide-code:\n            :hide-output:\n\n            from qiskit.test.ibmq_mock import mock_get_backend\n            mock_get_backend('FakeVigo')\n\n        .. jupyter-execute::\n\n            from qiskit import QuantumCircuit, execute, IBMQ\n            from qiskit.visualization import plot_error_map\n            %matplotlib inline\n\n            IBMQ.load_account()\n            provider = IBMQ.get_provider(hub='ibm-q')\n            backend = provider.get_backend('ibmq_vigo')\n            plot_error_map(backend)\n    "
    try:
        import seaborn as sns
    except ImportError:
        raise ImportError('Must have seaborn installed to use plot_error_map. To install, run "pip install seaborn".')
    if (not HAS_MATPLOTLIB):
        raise ImportError('Must have Matplotlib installed. To install, run "pip install matplotlib".')
    import matplotlib
    from matplotlib import get_backend
    import matplotlib.pyplot as plt
    import matplotlib.gridspec as gridspec
    from matplotlib import ticker
    color_map = sns.cubehelix_palette(reverse=True, as_cmap=True)
    props = backend.properties().to_dict()
    config = backend.configuration().to_dict()
    num_qubits = config['n_qubits']
    single_gate_errors = ([0] * num_qubits)
    for gate in props['gates']:
        if (gate['gate'] == 'u2'):
            _qubit = gate['qubits'][0]
            single_gate_errors[_qubit] = gate['parameters'][0]['value']
    single_gate_errors = (100 * np.asarray(single_gate_errors))
    avg_1q_err = np.mean(single_gate_errors)
    single_norm = matplotlib.colors.Normalize(vmin=min(single_gate_errors), vmax=max(single_gate_errors))
    q_colors = [color_map(single_norm(err)) for err in single_gate_errors]
    cmap = config['coupling_map']
    directed = False
    line_colors = []
    if cmap:
        directed = False
        if (num_qubits < 20):
            for edge in cmap:
                if (not ([edge[1], edge[0]] in cmap)):
                    directed = True
                    break
        cx_errors = []
        for line in cmap:
            for item in props['gates']:
                if (item['qubits'] == line):
                    cx_errors.append(item['parameters'][0]['value'])
                    break
            else:
                continue
        cx_errors = (100 * np.asarray(cx_errors))
        avg_cx_err = np.mean(cx_errors)
        cx_norm = matplotlib.colors.Normalize(vmin=min(cx_errors), vmax=max(cx_errors))
        line_colors = [color_map(cx_norm(err)) for err in cx_errors]
    read_err = []
    for qubit in range(num_qubits):
        for item in props['qubits'][qubit]:
            if (item['name'] == 'readout_error'):
                read_err.append(item['value'])
    read_err = (100 * np.asarray(read_err))
    avg_read_err = np.mean(read_err)
    max_read_err = np.max(read_err)
    fig = plt.figure(figsize=figsize)
    gridspec.GridSpec(nrows=2, ncols=3)
    grid_spec = gridspec.GridSpec(12, 12, height_ratios=(([1] * 11) + [0.5]), width_ratios=[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2])
    left_ax = plt.subplot(grid_spec[2:10, :1])
    main_ax = plt.subplot(grid_spec[:11, 1:11])
    right_ax = plt.subplot(grid_spec[2:10, 11:])
    bleft_ax = plt.subplot(grid_spec[(- 1), :5])
    if cmap:
        bright_ax = plt.subplot(grid_spec[(- 1), 7:])
    plot_gate_map(backend, qubit_color=q_colors, line_color=line_colors, qubit_size=28, line_width=5, plot_directed=directed, ax=main_ax)
    main_ax.axis('off')
    main_ax.set_aspect(1)
    if cmap:
        single_cb = matplotlib.colorbar.ColorbarBase(bleft_ax, cmap=color_map, norm=single_norm, orientation='horizontal')
        tick_locator = ticker.MaxNLocator(nbins=5)
        single_cb.locator = tick_locator
        single_cb.update_ticks()
        single_cb.update_ticks()
        bleft_ax.set_title('H error rate (%) [Avg. = {}]'.format(round(avg_1q_err, 3)))
    if (cmap is None):
        bleft_ax.axis('off')
        bleft_ax.set_title('H error rate (%) = {}'.format(round(avg_1q_err, 3)))
    if cmap:
        cx_cb = matplotlib.colorbar.ColorbarBase(bright_ax, cmap=color_map, norm=cx_norm, orientation='horizontal')
        tick_locator = ticker.MaxNLocator(nbins=5)
        cx_cb.locator = tick_locator
        cx_cb.update_ticks()
        bright_ax.set_title('CNOT error rate (%) [Avg. = {}]'.format(round(avg_cx_err, 3)))
    if (num_qubits < 10):
        num_left = num_qubits
        num_right = 0
    else:
        num_left = math.ceil((num_qubits / 2))
        num_right = (num_qubits - num_left)
    left_ax.barh(range(num_left), read_err[:num_left], align='center', color='#DDBBBA')
    left_ax.axvline(avg_read_err, linestyle='--', color='#212121')
    left_ax.set_yticks(range(num_left))
    left_ax.set_xticks([0, round(avg_read_err, 2), round(max_read_err, 2)])
    left_ax.set_yticklabels([str(kk) for kk in range(num_left)], fontsize=12)
    left_ax.invert_yaxis()
    left_ax.set_title('Readout Error (%)', fontsize=12)
    for spine in left_ax.spines.values():
        spine.set_visible(False)
    if num_right:
        right_ax.barh(range(num_left, num_qubits), read_err[num_left:], align='center', color='#DDBBBA')
        right_ax.axvline(avg_read_err, linestyle='--', color='#212121')
        right_ax.set_yticks(range(num_left, num_qubits))
        right_ax.set_xticks([0, round(avg_read_err, 2), round(max_read_err, 2)])
        right_ax.set_yticklabels([str(kk) for kk in range(num_left, num_qubits)], fontsize=12)
        right_ax.invert_yaxis()
        right_ax.invert_xaxis()
        right_ax.yaxis.set_label_position('right')
        right_ax.yaxis.tick_right()
        right_ax.set_title('Readout Error (%)', fontsize=12)
    else:
        right_ax.axis('off')
    for spine in right_ax.spines.values():
        spine.set_visible(False)
    if show_title:
        fig.suptitle('{name} Error Map'.format(name=backend.name()), fontsize=24, y=0.9)
    if (get_backend() in ['module://ipykernel.pylab.backend_inline', 'nbAgg']):
        plt.close(fig)
    return fig
Plots the error map of a given backend.

Args:
    backend (IBMQBackend): Given backend.
    figsize (tuple): Figure size in inches.
    show_title (bool): Show the title or not.

Returns:
    Figure: A matplotlib figure showing error map.

Raises:
    VisualizationError: Input is not IBMQ backend.
    ImportError: If seaborn is not installed

Example:
    .. jupyter-execute::
        :hide-code:
        :hide-output:

        from qiskit.test.ibmq_mock import mock_get_backend
        mock_get_backend('FakeVigo')

    .. jupyter-execute::

        from qiskit import QuantumCircuit, execute, IBMQ
        from qiskit.visualization import plot_error_map
        %matplotlib inline

        IBMQ.load_account()
        provider = IBMQ.get_provider(hub='ibm-q')
        backend = provider.get_backend('ibmq_vigo')
        plot_error_map(backend)
def plot_error_map(backend, figsize=(12, 9), show_title=True):
    "Plots the error map of a given backend.\n\n    Args:\n        backend (IBMQBackend): Given backend.\n        figsize (tuple): Figure size in inches.\n        show_title (bool): Show the title or not.\n\n    Returns:\n        Figure: A matplotlib figure showing error map.\n\n    Raises:\n        VisualizationError: Input is not IBMQ backend.\n        ImportError: If seaborn is not installed\n\n    Example:\n        .. jupyter-execute::\n            :hide-code:\n            :hide-output:\n\n            from qiskit.test.ibmq_mock import mock_get_backend\n            mock_get_backend('FakeVigo')\n\n        .. jupyter-execute::\n\n            from qiskit import QuantumCircuit, execute, IBMQ\n            from qiskit.visualization import plot_error_map\n            %matplotlib inline\n\n            IBMQ.load_account()\n            provider = IBMQ.get_provider(hub='ibm-q')\n            backend = provider.get_backend('ibmq_vigo')\n            plot_error_map(backend)\n    "
    try:
        import seaborn as sns
    except ImportError:
        raise ImportError('Must have seaborn installed to use plot_error_map. To install, run "pip install seaborn".')
    if (not HAS_MATPLOTLIB):
        raise ImportError('Must have Matplotlib installed. To install, run "pip install matplotlib".')
    import matplotlib
    from matplotlib import get_backend
    import matplotlib.pyplot as plt
    import matplotlib.gridspec as gridspec
    from matplotlib import ticker
    color_map = sns.cubehelix_palette(reverse=True, as_cmap=True)
    props = backend.properties().to_dict()
    config = backend.configuration().to_dict()
    num_qubits = config['n_qubits']
    single_gate_errors = ([0] * num_qubits)
    for gate in props['gates']:
        if (gate['gate'] == 'u2'):
            _qubit = gate['qubits'][0]
            single_gate_errors[_qubit] = gate['parameters'][0]['value']
    single_gate_errors = (100 * np.asarray(single_gate_errors))
    avg_1q_err = np.mean(single_gate_errors)
    single_norm = matplotlib.colors.Normalize(vmin=min(single_gate_errors), vmax=max(single_gate_errors))
    q_colors = [color_map(single_norm(err)) for err in single_gate_errors]
    cmap = config['coupling_map']
    directed = False
    line_colors = []
    if cmap:
        directed = False
        if (num_qubits < 20):
            for edge in cmap:
                if (not ([edge[1], edge[0]] in cmap)):
                    directed = True
                    break
        cx_errors = []
        for line in cmap:
            for item in props['gates']:
                if (item['qubits'] == line):
                    cx_errors.append(item['parameters'][0]['value'])
                    break
            else:
                continue
        cx_errors = (100 * np.asarray(cx_errors))
        avg_cx_err = np.mean(cx_errors)
        cx_norm = matplotlib.colors.Normalize(vmin=min(cx_errors), vmax=max(cx_errors))
        line_colors = [color_map(cx_norm(err)) for err in cx_errors]
    read_err = []
    for qubit in range(num_qubits):
        for item in props['qubits'][qubit]:
            if (item['name'] == 'readout_error'):
                read_err.append(item['value'])
    read_err = (100 * np.asarray(read_err))
    avg_read_err = np.mean(read_err)
    max_read_err = np.max(read_err)
    fig = plt.figure(figsize=figsize)
    gridspec.GridSpec(nrows=2, ncols=3)
    grid_spec = gridspec.GridSpec(12, 12, height_ratios=(([1] * 11) + [0.5]), width_ratios=[2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2])
    left_ax = plt.subplot(grid_spec[2:10, :1])
    main_ax = plt.subplot(grid_spec[:11, 1:11])
    right_ax = plt.subplot(grid_spec[2:10, 11:])
    bleft_ax = plt.subplot(grid_spec[(- 1), :5])
    if cmap:
        bright_ax = plt.subplot(grid_spec[(- 1), 7:])
    plot_gate_map(backend, qubit_color=q_colors, line_color=line_colors, qubit_size=28, line_width=5, plot_directed=directed, ax=main_ax)
    main_ax.axis('off')
    main_ax.set_aspect(1)
    if cmap:
        single_cb = matplotlib.colorbar.ColorbarBase(bleft_ax, cmap=color_map, norm=single_norm, orientation='horizontal')
        tick_locator = ticker.MaxNLocator(nbins=5)
        single_cb.locator = tick_locator
        single_cb.update_ticks()
        single_cb.update_ticks()
        bleft_ax.set_title('H error rate (%) [Avg. = {}]'.format(round(avg_1q_err, 3)))
    if (cmap is None):
        bleft_ax.axis('off')
        bleft_ax.set_title('H error rate (%) = {}'.format(round(avg_1q_err, 3)))
    if cmap:
        cx_cb = matplotlib.colorbar.ColorbarBase(bright_ax, cmap=color_map, norm=cx_norm, orientation='horizontal')
        tick_locator = ticker.MaxNLocator(nbins=5)
        cx_cb.locator = tick_locator
        cx_cb.update_ticks()
        bright_ax.set_title('CNOT error rate (%) [Avg. = {}]'.format(round(avg_cx_err, 3)))
    if (num_qubits < 10):
        num_left = num_qubits
        num_right = 0
    else:
        num_left = math.ceil((num_qubits / 2))
        num_right = (num_qubits - num_left)
    left_ax.barh(range(num_left), read_err[:num_left], align='center', color='#DDBBBA')
    left_ax.axvline(avg_read_err, linestyle='--', color='#212121')
    left_ax.set_yticks(range(num_left))
    left_ax.set_xticks([0, round(avg_read_err, 2), round(max_read_err, 2)])
    left_ax.set_yticklabels([str(kk) for kk in range(num_left)], fontsize=12)
    left_ax.invert_yaxis()
    left_ax.set_title('Readout Error (%)', fontsize=12)
    for spine in left_ax.spines.values():
        spine.set_visible(False)
    if num_right:
        right_ax.barh(range(num_left, num_qubits), read_err[num_left:], align='center', color='#DDBBBA')
        right_ax.axvline(avg_read_err, linestyle='--', color='#212121')
        right_ax.set_yticks(range(num_left, num_qubits))
        right_ax.set_xticks([0, round(avg_read_err, 2), round(max_read_err, 2)])
        right_ax.set_yticklabels([str(kk) for kk in range(num_left, num_qubits)], fontsize=12)
        right_ax.invert_yaxis()
        right_ax.invert_xaxis()
        right_ax.yaxis.set_label_position('right')
        right_ax.yaxis.tick_right()
        right_ax.set_title('Readout Error (%)', fontsize=12)
    else:
        right_ax.axis('off')
    for spine in right_ax.spines.values():
        spine.set_visible(False)
    if show_title:
        fig.suptitle('{name} Error Map'.format(name=backend.name()), fontsize=24, y=0.9)
    if (get_backend() in ['module://ipykernel.pylab.backend_inline', 'nbAgg']):
        plt.close(fig)
    return fig