Exemplo n.º 1
0
def test_add_annotated_shape_multi_plot(multi_plot_fixture):
    multi_plot_fixture.add_hline(y=1, annotation_text="A")
    multi_plot_fixture.add_vline(x=2, annotation_text="B")
    multi_plot_fixture.add_hrect(y0=3, y1=4, annotation_text="C")
    multi_plot_fixture.add_vrect(x0=5, x1=6, annotation_text="D")
    ax_nums = ["", "2", "3", "4"]
    ret = len(multi_plot_fixture.layout.annotations) == 16
    for sh, d in zip(
        multi_plot_fixture.layout.annotations,
        [
            {"text": "A", "xref": "x%s domain" % (n,), "yref": "y%s" % (n,)}
            for n in ax_nums
        ]
        + [
            {"text": "B", "xref": "x%s" % (n,), "yref": "y%s domain" % (n,)}
            for n in ax_nums
        ]
        + [
            {"text": "C", "xref": "x%s domain" % (n,), "yref": "y%s" % (n,)}
            for n in ax_nums
        ]
        + [
            {"text": "D", "xref": "x%s" % (n,), "yref": "y%s domain" % (n,)}
            for n in ax_nums
        ],
    ):
        ret &= _cmp_partial_dict(sh, d)
    assert ret
Exemplo n.º 2
0
def test_specify_annotation_as_dict(multi_plot_fixture):
    multi_plot_fixture.add_vrect(
        row=2,
        col=2,
        x0=2,
        x1=9,
        annotation=dict(text="A", x=5.5, xanchor="center"),
        annotation_position="outside right",
    )
    ret = len(multi_plot_fixture.layout.annotations) == 1
    for sh, d in zip(
        multi_plot_fixture.layout.annotations,
        [
            {
                "text": "A",
                "x": 5.5,
                "xanchor": "center",
                "y": 0.5,
                "yanchor": "middle",
                "xref": "x4",
                "yref": "y4 domain",
            }
        ],
    ):
        ret &= _cmp_partial_dict(sh, d)
    assert ret
Exemplo n.º 3
0
def test_position_order(multi_plot_fixture):
    multi_plot_fixture.add_hrect(
        y0=3,
        y1=6,
        row=1,
        col=2,
        annotation_text="Position order",
        annotation_position="left bottom outside",
    )
    ret = len(multi_plot_fixture.layout.annotations) == 1
    for sh, d in zip(
        multi_plot_fixture.layout.annotations,
        [
            dict(
                text="Position order",
                x=0,
                y=3,
                xanchor="left",
                yanchor="top",
                xref="x2 domain",
                yref="y2",
            )
        ],
    ):
        ret &= _cmp_partial_dict(sh, d)
    assert ret
Exemplo n.º 4
0
def test_add_annotated_shape_single_plot(single_plot_fixture):
    single_plot_fixture.add_hline(y=1, annotation_text="A")
    single_plot_fixture.add_vline(x=2, annotation_text="B")
    single_plot_fixture.add_hrect(y0=3, y1=4, annotation_text="C")
    single_plot_fixture.add_vrect(x0=5, x1=6, annotation_text="D")
    ret = len(single_plot_fixture.layout.annotations) == 4
    for sh, d in zip(
        single_plot_fixture.layout.annotations,
        [{"text": "A"}, {"text": "B"}, {"text": "C"}, {"text": "D"}],
    ):
        ret &= _cmp_partial_dict(sh, d)
    assert ret
Exemplo n.º 5
0
def test_default_annotation_positions(multi_plot_fixture):
    # default position is (inside) top right
    multi_plot_fixture.add_hrect(row=2, col=2, y0=1, y1=8, annotation_text="A")
    multi_plot_fixture.add_vline(row=2, col=1, x=4, annotation_text="B")
    # if position on {h,v}rect lacks inside/outside specifier it defaults to inside
    multi_plot_fixture.add_vrect(
        row=1, col=2, x0=3, x1=6, annotation_text="C", annotation_position="bottom left"
    )
    ret = len(multi_plot_fixture.layout.annotations) == 3
    for sh, d in zip(
        multi_plot_fixture.layout.annotations,
        [
            {
                "text": "A",
                "x": 1,
                "y": 8,
                "xanchor": "right",
                "yanchor": "top",
                "xref": "x4 domain",
                "yref": "y4",
            },
            {
                "text": "B",
                "x": 4,
                "y": 1,
                "xanchor": "left",
                "yanchor": "top",
                "xref": "x3",
                "yref": "y3 domain",
            },
            {
                "text": "C",
                "x": 3,
                "y": 0,
                "xanchor": "left",
                "yanchor": "bottom",
                "xref": "x2",
                "yref": "y2 domain",
            },
        ],
    ):
        ret &= _cmp_partial_dict(sh, d)
    assert ret
Exemplo n.º 6
0
def test_annotation_position_override(multi_plot_fixture):
    multi_plot_fixture.add_hline(
        row=2,
        col=2,
        y=1,
        annotation_text="A",
        annotation_position="top left",
        annotation_xanchor="center",
    )
    multi_plot_fixture.add_vline(
        row=1,
        col=2,
        x=2,
        annotation_text="B",
        annotation_position="bottom left",
        annotation_yanchor="middle",
    )
    multi_plot_fixture.add_hrect(
        row=2,
        col=1,
        y0=3,
        y1=5,
        annotation_text="C",
        annotation_position="outside left",
        annotation_xanchor="center",
    )
    multi_plot_fixture.add_vrect(
        row=1,
        col=1,
        x0=4,
        x1=6,
        annotation_text="D",
        annotation_position="inside bottom right",
        annotation_yanchor="middle",
        annotation_xanchor="center",
    )
    ret = len(multi_plot_fixture.layout.annotations) == 4
    for sh, d in zip(
        multi_plot_fixture.layout.annotations,
        [
            {
                "xanchor": "center",
                "xref": "x4 domain",
                "yref": "y4",
                "x": 0,
                "y": 1,
                "text": "A",
            },
            {
                "yanchor": "middle",
                "xref": "x2",
                "yref": "y2 domain",
                "x": 2,
                "y": 0,
                "text": "B",
            },
            {
                "xanchor": "center",
                "xref": "x3 domain",
                "yref": "y3",
                "x": 0,
                "y": 4,
                "text": "C",
            },
            {
                "xanchor": "center",
                "yanchor": "middle",
                "xref": "x",
                "yref": "y domain",
                "x": 6,
                "y": 0,
                "text": "D",
            },
        ],
    ):
        ret &= _cmp_partial_dict(sh, d)
    assert ret