Exemplo n.º 1
0
def test_h_and_v_bars():
    fig, ax = plt.subplots()
    ax.bar(left=D['multi_left'],
           height=D['multi_height'],
           width=10,
           color='green',
           alpha=.5)
    # changing height 10 -> 14 because ValueError if bargap not in [0, 1]
    ax.barh(bottom=D['multi_bottom'],
            width=D['multi_width'],
            height=14,
            color='red',
            alpha=.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        d1, d2 = strip_dict_params(data_dict,
                                   H_AND_V_BARS['data'][data_no],
                                   ignore=['uid'])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   H_AND_V_BARS['layout'])
    assert equivalent, msg
Exemplo n.º 2
0
def test_h_and_v_bars():
    fig, ax = plt.subplots()
    ax.bar(
        left=D["multi_left"],
        height=D["multi_height"],
        width=10,
        color="green",
        alpha=0.5,
    )
    # changing height 10 -> 14 because ValueError if bargap not in [0, 1]
    ax.barh(
        bottom=D["multi_bottom"],
        width=D["multi_width"],
        height=14,
        color="red",
        alpha=0.5,
    )
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   H_AND_V_BARS["data"][data_no],
                                   ignore=["uid"])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig["layout"],
                                   H_AND_V_BARS["layout"])
    assert equivalent, msg
Exemplo n.º 3
0
def test_complicated_line():
    fig, ax = plt.subplots()
    ax.plot(D["x1"], D["y1"], "ro", markersize=10, alpha=0.5, label="one")
    ax.plot(D["x1"], D["y1"], "-b", linewidth=2, alpha=0.7, label="two")
    ax.plot(
        D["x2"],
        D["y2"],
        "b+",
        markeredgewidth=2,
        markersize=10,
        alpha=0.6,
        label="three",
    )
    ax.plot(D["x2"], D["y2"], "--r", linewidth=2, alpha=0.8, label="four")
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   COMPLICATED_LINE["data"][data_no],
                                   ignore=["uid"])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig["layout"],
                                   COMPLICATED_LINE["layout"])
    assert equivalent, msg
Exemplo n.º 4
0
def test_lines_data():
    fig, ax = plt.subplots()
    ax.plot(D["x1"], D["y1"])
    ax.plot(D["x2"], D["y2"])
    renderer = run_fig(fig)
    for xi, xf, yi, yf in zip(
            renderer.plotly_fig["data"][0]["x"],
            D["x1"],
            renderer.plotly_fig["data"][0]["y"],
            D["y1"],
    ):
        assert xi == xf, (str(renderer.plotly_fig["data"][0]["x"]) +
                          " is not " + str(D["x1"]))
        assert yi == yf, (str(renderer.plotly_fig["data"][0]["y"]) +
                          " is not " + str(D["y1"]))
    for xi, xf, yi, yf in zip(
            renderer.plotly_fig["data"][1]["x"],
            D["x2"],
            renderer.plotly_fig["data"][1]["y"],
            D["y2"],
    ):
        assert xi == xf, (str(renderer.plotly_fig["data"][1]["x"]) +
                          " is not " + str(D["x2"]))
        assert yi == yf, (str(renderer.plotly_fig["data"][0]["y"]) +
                          " is not " + str(D["y2"]))
Exemplo n.º 5
0
def test_bar_data():
    fig, ax = plt.subplots()
    ax.bar(D['x1'], D['y1'])
    renderer = run_fig(fig)
    for yi, yf in zip(renderer.plotly_fig['data'][0]['y'], D['y1']):
        assert yi == yf, str(
            renderer.plotly_fig['data'][0]['y']) + ' is not ' + str(D['y1'])
Exemplo n.º 6
0
def test_bar_data():
    fig, ax = plt.subplots()
    ax.bar(D["x1"], D["y1"])
    renderer = run_fig(fig)
    for yi, yf in zip(renderer.plotly_fig["data"][0]["y"], D["y1"]):
        assert yi == yf, (str(renderer.plotly_fig["data"][0]["y"]) +
                          " is not " + str(D["y1"]))
Exemplo n.º 7
0
def test_bars_data():
    fig, ax = plt.subplots()
    ax.bar(D["x1"], D["y1"], color="r")
    ax.barh(D["x2"], D["y2"], color="b")
    renderer = run_fig(fig)
    for yi, yf in zip(renderer.plotly_fig["data"][0]["y"], D["y1"]):
        assert yi == yf, str(renderer.plotly_fig["data"][0]["y"]) + " is not " + str(D["y1"])
    for xi, yf in zip(renderer.plotly_fig["data"][1]["x"], D["y2"]):
        assert xi == yf, str(renderer.plotly_fig["data"][1]["x"]) + " is not " + str(D["y2"])
Exemplo n.º 8
0
def test_simple_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D["x1"], D["y1"])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        equivalent, msg = compare_dict(data_dict, SIMPLE_SCATTER["data"][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig["layout"], SIMPLE_SCATTER["layout"])
    assert equivalent, msg
Exemplo n.º 9
0
def test_line_data():
    fig, ax = plt.subplots()
    ax.plot(D["x1"], D["y1"])
    renderer = run_fig(fig)
    for xi, xf, yi, yf in zip(
        renderer.plotly_fig["data"][0]["x"], D["x1"], renderer.plotly_fig["data"][0]["y"], D["y1"]
    ):
        assert xi == xf, str(renderer.plotly_fig["data"][0]["x"]) + " is not " + str(D["x1"])
        assert yi == yf, str(renderer.plotly_fig["data"][0]["y"]) + " is not " + str(D["y1"])
Exemplo n.º 10
0
def test_double_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D["x1"], D["y1"], color="red", s=121, marker="^", alpha=0.5)
    ax.scatter(D["x2"], D["y2"], color="purple", s=64, marker="s", alpha=0.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        equivalent, msg = compare_dict(data_dict, DOUBLE_SCATTER["data"][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig["layout"], DOUBLE_SCATTER["layout"])
    assert equivalent, msg
Exemplo n.º 11
0
def test_line_data():
    fig, ax = plt.subplots()
    ax.plot(D['x1'], D['y1'])
    renderer = run_fig(fig)
    for xi, xf, yi, yf in zip(renderer.plotly_fig['data'][0]['x'], D['x1'],
                              renderer.plotly_fig['data'][0]['y'], D['y1']):
        assert xi == xf, str(
            renderer.plotly_fig['data'][0]['x']) + ' is not ' + str(D['x1'])
        assert yi == yf, str(
            renderer.plotly_fig['data'][0]['y']) + ' is not ' + str(D['y1'])
Exemplo n.º 12
0
def test_simple_line():
    fig, ax = plt.subplots()
    ax.plot(D['x1'], D['y1'], label='simple')
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict, SIMPLE_LINE['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   SIMPLE_LINE['layout'])
    assert equivalent, msg
Exemplo n.º 13
0
def test_horizontal_bar():
    fig, ax = plt.subplots()
    ax.barh(bottom=D['bottom'], width=D['width'])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       HORIZONTAL_BAR['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   HORIZONTAL_BAR['layout'])
    assert equivalent, msg
Exemplo n.º 14
0
def test_vertical_bar():
    fig, ax = plt.subplots()
    ax.bar(left=D['left'], height=D['height'])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       VERTICAL_BAR['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   VERTICAL_BAR['layout'])
    assert equivalent, msg
Exemplo n.º 15
0
def test_bars_data():
    fig, ax = plt.subplots()
    ax.bar(D["x1"], D["y1"], color="r")
    ax.barh(D["x2"], D["y2"], color="b")
    renderer = run_fig(fig)
    for yi, yf in zip(renderer.plotly_fig["data"][0]["y"], D["y1"]):
        assert yi == yf, (str(renderer.plotly_fig["data"][0]["y"]) +
                          " is not " + str(D["y1"]))
    for xi, yf in zip(renderer.plotly_fig["data"][1]["x"], D["y2"]):
        assert xi == yf, (str(renderer.plotly_fig["data"][1]["x"]) +
                          " is not " + str(D["y2"]))
Exemplo n.º 16
0
def test_vertical_bar():
    fig, ax = plt.subplots()
    ax.bar(left=D['left'], height=D['height'])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       VERTICAL_BAR['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   VERTICAL_BAR['layout'])
    assert equivalent, msg
Exemplo n.º 17
0
def test_simple_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D['x1'], D['y1'])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       SIMPLE_SCATTER['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   SIMPLE_SCATTER['layout'])
    assert equivalent, msg
Exemplo n.º 18
0
def test_bars_data():
    fig, ax = plt.subplots()
    ax.bar(D['x1'], D['y1'], color='r')
    ax.barh(D['x2'], D['y2'], color='b')
    renderer = run_fig(fig)
    for yi, yf in zip(renderer.plotly_fig['data'][0]['y'], D['y1']):
        assert yi == yf, str(
            renderer.plotly_fig['data'][0]['y']) + ' is not ' + str(D['y1'])
    for xi, yf in zip(renderer.plotly_fig['data'][1]['x'], D['y2']):
        assert xi == yf, str(
            renderer.plotly_fig['data'][1]['x']) + ' is not ' + str(D['y2'])
Exemplo n.º 19
0
def test_horizontal_bar():
    fig, ax = plt.subplots()
    ax.barh(bottom=D['bottom'], width=D['width'])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       HORIZONTAL_BAR['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   HORIZONTAL_BAR['layout'])
    assert equivalent, msg
Exemplo n.º 20
0
def test_double_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D['x1'], D['y1'], color='red', s=121, marker='^', alpha=0.5)
    ax.scatter(D['x2'], D['y2'], color='purple', s=64, marker='s', alpha=0.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       DOUBLE_SCATTER['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   DOUBLE_SCATTER['layout'])
    assert equivalent, msg
Exemplo n.º 21
0
def test_simple_line():
    fig, ax = plt.subplots()
    ax.plot(D["x1"], D["y1"], label="simple")
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(
            data_dict, SIMPLE_LINE["data"][data_no], ignore=["uid"]
        )

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig["layout"], SIMPLE_LINE["layout"])
    assert equivalent, msg
Exemplo n.º 22
0
def test_even_linear_scale():
    fig, ax = plt.subplots()
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    y = [10, 3, 100, 6, 45, 4, 80, 45, 3, 59]
    ax.plot(x, y)
    _ = ax.set_xticks(list(range(0, 20, 3)))
    _ = ax.set_yticks(list(range(0, 200, 13)))
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        equivalent, msg = compare_dict(data_dict, EVEN_LINEAR_SCALE["data"][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig["layout"], EVEN_LINEAR_SCALE["layout"])
    assert equivalent, msg
Exemplo n.º 23
0
def test_h_and_v_bars():
    fig, ax = plt.subplots()
    ax.bar(left=D['multi_left'], height=D['multi_height'],
           width=10, color='green', alpha=.5)
    ax.barh(bottom=D['multi_bottom'], width=D['multi_width'],
            height=10, color='red', alpha=.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       H_AND_V_BARS['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   H_AND_V_BARS['layout'])
    assert equivalent, msg
Exemplo n.º 24
0
def test_h_and_v_bars():
    fig, ax = plt.subplots()
    ax.bar(left=D['multi_left'], height=D['multi_height'],
           width=10, color='green', alpha=.5)
    ax.barh(bottom=D['multi_bottom'], width=D['multi_width'],
            height=10, color='red', alpha=.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       H_AND_V_BARS['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   H_AND_V_BARS['layout'])
    assert equivalent, msg
Exemplo n.º 25
0
def test_simple_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D['x1'], D['y1'])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        d1, d2 = strip_dict_params(data_dict, SIMPLE_SCATTER['data'][data_no], ignore=['uid'])
        print(d1)
        print('\n')
        print(d2)
        assert d1 == d2

    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   SIMPLE_SCATTER['layout'])
    assert equivalent, msg
Exemplo n.º 26
0
def test_even_linear_scale():
    fig, ax = plt.subplots()
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    y = [10, 3, 100, 6, 45, 4, 80, 45, 3, 59]
    ax.plot(x, y)
    _ = ax.set_xticks(list(range(0, 20, 3)))
    _ = ax.set_yticks(list(range(0, 200, 13)))
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       EVEN_LINEAR_SCALE['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   EVEN_LINEAR_SCALE['layout'])
    assert equivalent, msg
Exemplo n.º 27
0
def test_double_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D['x1'], D['y1'], color='red', s=121, marker='^', alpha=0.5)
    ax.scatter(D['x2'], D['y2'], color='purple', s=64, marker='s', alpha=0.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        d1, d2 = strip_dict_params(data_dict, DOUBLE_SCATTER['data'][data_no], ignore=['uid'])
        print(d1)
        print('\n')
        print(d2)
        assert d1 == d2

    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   DOUBLE_SCATTER['layout'])
    assert equivalent, msg
Exemplo n.º 28
0
def test_complicated_line():
    fig, ax = plt.subplots()
    ax.plot(D['x1'], D['y1'], 'ro', markersize=10, alpha=.5, label='one')
    ax.plot(D['x1'], D['y1'], '-b', linewidth=2, alpha=.7, label='two')
    ax.plot(D['x2'], D['y2'], 'b+', markeredgewidth=2,
            markersize=10, alpha=.6, label='three')
    ax.plot(D['x2'], D['y2'], '--r', linewidth=2, alpha=.8, label='four')
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       COMPLICATED_LINE['data'][data_no])
        assert equivalent, msg
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   COMPLICATED_LINE['layout'])
    assert equivalent, msg
Exemplo n.º 29
0
def test_vertical_bar():
    fig, ax = plt.subplots()
    ax.bar(left=D["left"], height=D["height"])
    renderer = run_fig(fig)

    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   VERTICAL_BAR["data"][data_no],
                                   ignore=["uid"])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig["layout"],
                                   VERTICAL_BAR["layout"])
    assert equivalent, msg
Exemplo n.º 30
0
def test_horizontal_bar():
    fig, ax = plt.subplots()
    ax.barh(bottom=D["bottom"], width=D["width"])
    renderer = run_fig(fig)

    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   HORIZONTAL_BAR["data"][data_no],
                                   ignore=["uid"])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig["layout"],
                                   HORIZONTAL_BAR["layout"])
    assert equivalent, msg
Exemplo n.º 31
0
def test_simple_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D["x1"], D["y1"])
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   SIMPLE_SCATTER["data"][data_no],
                                   ignore=["uid"])
        print(d1)
        print("\n")
        print(d2)
        assert d1 == d2

    equivalent, msg = compare_dict(renderer.plotly_fig["layout"],
                                   SIMPLE_SCATTER["layout"])
    assert equivalent, msg
Exemplo n.º 32
0
def test_blank_subplots():
    fig = plt.figure()
    gs = GridSpec(4, 6)
    ax1 = fig.add_subplot(gs[0, 1])
    ax1.plot(D['x1'], D['y1'])
    fig.add_subplot(gs[1, 1])
    fig.add_subplot(gs[2:, 1])
    fig.add_subplot(gs[0, 2:])
    fig.add_subplot(gs[1:3, 2:4])
    fig.add_subplot(gs[3, 2:5])
    fig.add_subplot(gs[1:3, 4:])
    fig.add_subplot(gs[3, 5])
    gs.update(hspace=.6, wspace=.6)
    renderer = run_fig(fig)
    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   BLANK_SUBPLOTS['layout'])
    assert equivalent, msg
Exemplo n.º 33
0
def test_double_scatter():
    fig, ax = plt.subplots()
    ax.scatter(D["x1"], D["y1"], color="red", s=121, marker="^", alpha=0.5)
    ax.scatter(D["x2"], D["y2"], color="purple", s=64, marker="s", alpha=0.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   DOUBLE_SCATTER["data"][data_no],
                                   ignore=["uid"])
        print(d1)
        print("\n")
        print(d2)
        assert d1 == d2

    equivalent, msg = compare_dict(renderer.plotly_fig["layout"],
                                   DOUBLE_SCATTER["layout"])
    assert equivalent, msg
Exemplo n.º 34
0
def test_h_and_v_bars():
    fig, ax = plt.subplots()
    ax.bar(left=D['multi_left'], height=D['multi_height'],
           width=10, color='green', alpha=.5)
    # changing height 10 -> 14 because ValueError if bargap not in [0, 1]
    ax.barh(bottom=D['multi_bottom'], width=D['multi_width'],
            height=14, color='red', alpha=.5)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        d1, d2 = strip_dict_params(data_dict, H_AND_V_BARS['data'][data_no], ignore=['uid'])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   H_AND_V_BARS['layout'])
    assert equivalent, msg
Exemplo n.º 35
0
def test_even_linear_scale():
    fig, ax = plt.subplots()
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    y = [10, 3, 100, 6, 45, 4, 80, 45, 3, 59]
    ax.plot(x, y)
    _ = ax.set_xticks(list(range(0, 20, 3)), True)
    _ = ax.set_yticks(list(range(0, 200, 13)), True)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        # equivalent, msg = compare_dict(data_dict.to_plotly_json(),
        #                                EVEN_LINEAR_SCALE['data'][data_no].to_plotly_json())
        # assert equivalent, msg
        d1, d2 = strip_dict_params(data_dict, EVEN_LINEAR_SCALE['data'][data_no], ignore=['uid'])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   EVEN_LINEAR_SCALE['layout'])
    assert equivalent, msg
Exemplo n.º 36
0
def test_annotations():
    fig, ax = plt.subplots()
    ax.plot([1, 2, 3], 'b-')
    ax.plot([3, 2, 1], 'b-')
    ax.text(0.001, 0.999,
            'top-left', transform=ax.transAxes, va='top', ha='left')
    ax.text(0.001, 0.001,
            'bottom-left', transform=ax.transAxes, va='baseline', ha='left')
    ax.text(0.999, 0.999,
            'top-right', transform=ax.transAxes, va='top', ha='right')
    ax.text(0.999, 0.001,
            'bottom-right', transform=ax.transAxes, va='baseline', ha='right')
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        equivalent, msg = compare_dict(data_dict,
                                       ANNOTATIONS['data'][data_no])
        assert equivalent, msg
    for no, note in enumerate(renderer.plotly_fig['layout']['annotations']):
        equivalent, msg = compare_dict(note,
                                       ANNOTATIONS['layout']['annotations'][no])
        assert equivalent, msg
Exemplo n.º 37
0
def test_even_linear_scale():
    fig, ax = plt.subplots()
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    y = [10, 3, 100, 6, 45, 4, 80, 45, 3, 59]
    ax.plot(x, y)
    _ = ax.set_xticks(list(range(0, 20, 3)), True)
    _ = ax.set_yticks(list(range(0, 200, 13)), True)
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        # equivalent, msg = compare_dict(data_dict.to_plotly_json(),
        #                                EVEN_LINEAR_SCALE['data'][data_no].to_plotly_json())
        # assert equivalent, msg
        d1, d2 = strip_dict_params(data_dict,
                                   EVEN_LINEAR_SCALE['data'][data_no],
                                   ignore=['uid'])

        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg

    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   EVEN_LINEAR_SCALE['layout'])
    assert equivalent, msg
Exemplo n.º 38
0
def test_annotations():
    fig, ax = plt.subplots()
    ax.plot([1, 2, 3], "b-")
    ax.plot([3, 2, 1], "b-")
    ax.text(0.001,
            0.999,
            "top-left",
            transform=ax.transAxes,
            va="top",
            ha="left")
    ax.text(0.001,
            0.001,
            "bottom-left",
            transform=ax.transAxes,
            va="baseline",
            ha="left")
    ax.text(0.999,
            0.999,
            "top-right",
            transform=ax.transAxes,
            va="top",
            ha="right")
    ax.text(0.999,
            0.001,
            "bottom-right",
            transform=ax.transAxes,
            va="baseline",
            ha="right")
    renderer = run_fig(fig)
    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   ANNOTATIONS["data"][data_no],
                                   ignore=["uid"])
        equivalent, msg = compare_dict(d1, d2)
        assert equivalent, msg
    for no, note in enumerate(renderer.plotly_fig["layout"]["annotations"]):
        equivalent, msg = compare_dict(
            note, ANNOTATIONS["layout"]["annotations"][no])
        assert equivalent, msg
Exemplo n.º 39
0
def test_blank_subplots():
    fig = plt.figure()
    gs = GridSpec(4, 6)
    ax1 = fig.add_subplot(gs[0, 1])
    ax1.plot(D['x1'], D['y1'])
    fig.add_subplot(gs[1, 1])
    fig.add_subplot(gs[2:, 1])
    fig.add_subplot(gs[0, 2:])
    fig.add_subplot(gs[1:3, 2:4])
    fig.add_subplot(gs[3, 2:5])
    fig.add_subplot(gs[1:3, 4:])
    fig.add_subplot(gs[3, 5])
    gs.update(hspace=.6, wspace=.6)
    renderer = run_fig(fig)

    for data_no, data_dict in enumerate(renderer.plotly_fig['data']):
        d1, d2 = strip_dict_params(data_dict, BLANK_SUBPLOTS['data'][data_no],
                                   ignore=['uid'])
        equivalent, msg = compare_dict(d1, d2)

    equivalent, msg = compare_dict(renderer.plotly_fig['layout'],
                                   BLANK_SUBPLOTS['layout'])
    assert equivalent, msg
Exemplo n.º 40
0
def test_blank_subplots():
    fig = plt.figure()
    gs = GridSpec(4, 6)
    ax1 = fig.add_subplot(gs[0, 1])
    ax1.plot(D["x1"], D["y1"])
    fig.add_subplot(gs[1, 1])
    fig.add_subplot(gs[2:, 1])
    fig.add_subplot(gs[0, 2:])
    fig.add_subplot(gs[1:3, 2:4])
    fig.add_subplot(gs[3, 2:5])
    fig.add_subplot(gs[1:3, 4:])
    fig.add_subplot(gs[3, 5])
    gs.update(hspace=0.6, wspace=0.6)
    renderer = run_fig(fig)

    for data_no, data_dict in enumerate(renderer.plotly_fig["data"]):
        d1, d2 = strip_dict_params(data_dict,
                                   BLANK_SUBPLOTS["data"][data_no],
                                   ignore=["uid"])
        equivalent, msg = compare_dict(d1, d2)

    equivalent, msg = compare_dict(renderer.plotly_fig["layout"],
                                   BLANK_SUBPLOTS["layout"])
    assert equivalent, msg
Exemplo n.º 41
0
def test_bar_data():
    fig, ax = plt.subplots()
    ax.bar(D["x1"], D["y1"])
    renderer = run_fig(fig)
    for yi, yf in zip(renderer.plotly_fig["data"][0]["y"], D["y1"]):
        assert yi == yf, str(renderer.plotly_fig["data"][0]["y"]) + " is not " + str(D["y1"])