def test_default_annotation(ax):
    """Tests that the default annotation is '.2g' format on float(value)."""
    row_col_list = ((0, 5), (8, 1), (7, 0), (13, 5), (1, 6), (3, 2), (2, 8))
    qubits = [grid_qubit.GridQubit(row, col) for (row, col) in row_col_list]
    values = ['3.752', '42', '-5.27e8', '-7.34e-9', 732, 0.432, 3.9753e28]
    test_value_map = {(qubit,): value for qubit, value in zip(qubits, values)}
    test_row_col_map = {rc: value for rc, value in zip(row_col_list, values)}
    random_heatmap = heatmap.Heatmap(test_value_map)
    random_heatmap.plot(ax)
    actual_texts = set()
    for artist in ax.get_children():
        if isinstance(artist, mpl.text.Text):
            col, row = artist.get_position()
            text = artist.get_text()
            actual_texts.add(((row, col), text))
    expected_texts = set(
        (qubit, format(float(value), '.2g')) for qubit, value in test_row_col_map.items()
    )
    assert expected_texts.issubset(actual_texts)
Tests that the default annotation is '.2g' format on float(value).
cirq-core/cirq/vis/heatmap_test.py