Пример #1
0
def test_y_axis_direction():
    fig = tplot.Figure(width=80, height=24, y_axis_direction="down")
    for dataset_name, data in datasets.items():
        fig.clear()
        fig.scatter(data[0], data[1])
        assert equal_to_file(str(fig), f"y_axis_down_{dataset_name}.txt")

    fig = tplot.Figure(width=80, height=24, y_axis_direction="up")
    fig.image(gradient)
    assert equal_to_file(str(fig), "y_axis_up.txt")
Пример #2
0
def test_colors():
    fig = tplot.Figure(width=80, height=24, legendloc="bottomright")
    for i, color in enumerate(
        ["red", "green", "blue", "yellow", "magenta", "cyan", "grey",
         "white"]):
        fig.scatter([i], [i], color=color, label=color)
    assert equal_to_file(str(fig), "colors.txt")
Пример #3
0
def test_legend():
    for legendloc in ("topleft", "topright", "bottomright", "bottomleft"):
        fig = tplot.Figure(width=80, height=24, legendloc=legendloc)
        fig.scatter(range(5), label="First")
        fig.line(range(-5, 0), label="Second")
        fig.scatter(range(5, 10), marker="3", label="Third")
        assert equal_to_file(str(fig), f"legendloc_{legendloc}.txt")
Пример #4
0
def test_image():
    fig = tplot.Figure(width=80, height=24)
    fig.image(gradient)
    assert equal_to_file(str(fig), "image.txt")

    fig.clear()
    fig.image((gradient * 128).astype(np.uint8))
    assert equal_to_file(str(fig), "image_big_values.txt")

    fig.clear()
    fig.image(gradient * -1e-3)
    assert equal_to_file(str(fig), "image_small_values.txt")

    fig.clear()
    fig.image(gradient, vmin=-1, vmax=1)
    assert equal_to_file(str(fig), "image_vmin_vmax.txt")

    fig.clear()
    fig.image(gradient, cmap="ascii")
    assert equal_to_file(str(fig), "image_ascii.txt")

    fig.clear()
    cameraman = np.array(Image.open("tests/cameraman.png"))
    fig.image(cameraman)
    assert equal_to_file(str(fig), "image_cameraman.txt")
Пример #5
0
def test_y_only():
    fig = tplot.Figure(width=80, height=24)
    fig.scatter(range(10))
    with open(reference_figures_dir / "y_only.txt",
              "w" if generate else "r") as f:
        if generate:
            f.write(str(fig))
        else:
            assert str(fig) == f.read()
Пример #6
0
def test_ascii_fallback():
    fig = tplot.Figure(width=80, height=24, ascii=True)
    for dataset_name, data in datasets.items():
        fig.clear()
        fig.scatter(data[0], data[1])
        assert ascii_only(str(fig))

    fig.clear()
    fig.image(gradient)
    assert ascii_only(str(fig))
Пример #7
0
def test_axis_labels():
    fig = tplot.Figure(
        xlabel="x axis label goes here",
        ylabel="y axis label goes here",
        title="Title goes here",
        width=80,
        height=40,
        legendloc="bottomright",
    )
    fig.scatter(range(10), label="Legend label goes here")
    assert equal_to_file(str(fig), "axis_labels.txt")
Пример #8
0
def test_braille():
    fig = tplot.Figure(width=80, height=24)
    for dataset_name, data in datasets.items():
        fig.clear()
        fig.scatter(data[0], data[1], marker="braille", color="red")
        assert equal_to_file(str(fig), f"braille_scatter_{dataset_name}.txt")

        fig.clear()
        fig.line(data[0], data[1], marker="braille", color="green")
        assert equal_to_file(str(fig), f"braille_line_{dataset_name}.txt")

        fig.clear()
        fig.bar(data[0], data[1], marker="braille", color="blue")
        assert equal_to_file(str(fig), f"braille_bar_{dataset_name}.txt")

        fig.clear()
        fig.hbar(data[0], data[1], marker="braille")
        assert equal_to_file(str(fig), f"braille_hbar_{dataset_name}.txt")
Пример #9
0
def test_hbar():
    fig = tplot.Figure(width=80, height=24)
    for dataset_name, data in datasets.items():
        fig.clear()
        fig.hbar(data[0], data[1])
        assert equal_to_file(str(fig), f"hbar_{dataset_name}.txt")
Пример #10
0
def test_text():
    fig = tplot.Figure(width=80, height=24)
    fig.text(x=4, y=0, text="testing text")
    fig.text(x=4, y=-1, text="testing colored text", color="red")
    fig.text(x=9, y=8, text="testing text at right boundary")
    assert equal_to_file(str(fig), "text.txt")