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
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
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
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
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
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
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
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
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
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