How to use the termplotlib.figure function in termplotlib

To help you get started, we’ve selected a few termplotlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / termplotlib / test / test_figure.py View on Github external
def test_simple():
    fig = tpl.figure()
    fig.aprint("abc")
    string = fig.get_string()
    assert string == """abc"""
    return
github nschloe / termplotlib / test / test_plot.py View on Github external
def test_plot():
    x = numpy.linspace(0, 2 * numpy.pi, 10)
    y = numpy.sin(x)

    fig = tpl.figure()
    fig.plot(x, y, label="data", width=50, height=15)
    string = fig.get_string()

    ref = """    1 +---------------------------------------+
  0.8 |    **     **                          |
  0.6 |   *         **           data ******* |
  0.4 | **                                    |
  0.2 |*              **                      |
    0 |                 **                    |
      |                                   *   |
 -0.2 |                   **            **    |
 -0.4 |                     **         *      |
 -0.6 |                              **       |
 -0.8 |                       **** **         |
   -1 +---------------------------------------+
      0     1    2     3     4     5    6     7"""
github nschloe / termplotlib / test / test_hist.py View on Github external
def test_horizontal_ascii():
    numpy.random.seed(123)
    sample = numpy.random.normal(size=1000)
    counts, bin_edges = numpy.histogram(sample)
    fig = tpl.figure()
    fig.hist(counts, bin_edges, orientation="horizontal", force_ascii=True)
    string = fig.get_string()

    assert (
        string
        == """\
-3.23e+00 - -2.55e+00  [  7]  *
-2.55e+00 - -1.87e+00  [ 27]  ****
-1.87e+00 - -1.19e+00  [ 95]  **************
-1.19e+00 - -5.10e-01  [183]  **************************
-5.10e-01 - +1.70e-01  [286]  ****************************************
+1.70e-01 - +8.51e-01  [202]  *****************************
+8.51e-01 - +1.53e+00  [142]  ********************
+1.53e+00 - +2.21e+00  [ 49]  *******
+2.21e+00 - +2.89e+00  [  7]  *
+2.89e+00 - +3.57e+00  [  2]  *\
github nschloe / termplotlib / test / test_figure.py View on Github external
def test_padding_1b():
    fig = tpl.figure(padding=(1,))
    fig.aprint("abc")
    string = fig.get_string()
    assert (
        string
        == """
 abc
"""
    )
    return
github nschloe / termplotlib / test / test_hist.py View on Github external
@pytest.mark.skipif(
    sys.stdout.encoding not in ["UTF-8", "UTF8"],
    reason="Need UTF-8 terminal (not {})".format(sys.stdout.encoding),
)
def test_vertical_strip():
    numpy.random.seed(20)
    sample = numpy.random.normal(size=10000)
    counts, bin_edges = numpy.histogram(sample)
    fig = tpl.figure()
    fig.hist(counts, bin_edges, grid=[5, 8], strip=True)
    string = fig.get_string()

    assert (
        string
        == """\
   ▉▆
   ▉█
   ▉█
  ▁▉█
  █▉█
  █▉██
  █▉██
 ▁█▉██
 ██▉██▃
▃██▉██▉▂\
github nschloe / termplotlib / test / test_hist.py View on Github external
@pytest.mark.skipif(
    sys.stdout.encoding not in ["UTF-8", "UTF8"],
    reason="Need UTF-8 terminal (not {})".format(sys.stdout.encoding),
)
def test_vertical():
    numpy.random.seed(123)
    sample = numpy.random.normal(size=1000)
    counts, bin_edges = numpy.histogram(sample, bins=40)
    fig = tpl.figure()
    fig.hist(counts, bin_edges)
    fig.show()

    string = fig.get_string()

    assert (
        string
        == """\
                  ▆█
                ▄▄██
               ▃█████
              ▁██████▃  ▅
            ▂ ████████▇▅█
           ▂█▅████████████
          ▂███████████████▃▂
        ▂▃██████████████████▃▁
github nschloe / termplotlib / test / test_barh.py View on Github external
@pytest.mark.skipif(
    sys.stdout.encoding not in ["UTF-8", "UTF8"],
    reason="Need UTF-8 terminal (not {})".format(sys.stdout.encoding),
)
def test_barh():
    fig = tpl.figure()
    fig.barh([3, 10, 5, 2], ["Cats", "Dogs", "Cows", "Geese"])
    # fig.show()
    string = fig.get_string()

    assert (
        string
        == """\
Cats   [ 3]  ████████████
Dogs   [10]  ████████████████████████████████████████
Cows   [ 5]  ████████████████████
Geese  [ 2]  ████████\
"""
    )
    return
github nschloe / termplotlib / test / test_barh.py View on Github external
@pytest.mark.skipif(
    sys.stdout.encoding not in ["UTF-8", "UTF8"],
    reason="Need UTF-8 terminal (not {})".format(sys.stdout.encoding),
)
def test_barh_floats():
    fig = tpl.figure()
    fig.barh([0.3, 0.4, 0.6, 0.2], ["Cats", "Dogs", "Cows", "Geese"])
    # fig.show()
    string = fig.get_string()

    assert (
        string
        == """\
Cats   [0.3]  ████████████████████
Dogs   [0.4]  ██████████████████████████▋
Cows   [0.6]  ████████████████████████████████████████
Geese  [0.2]  █████████████▍\
"""
    )
    return
github nschloe / termplotlib / test / test_plot.py View on Github external
def test_plot_lim():
    x = numpy.linspace(0, 2 * numpy.pi, 10)
    y = numpy.sin(x)

    fig = tpl.figure()
    fig.plot(
        x,
        y,
        label="data",
        width=50,
        height=15,
        xlim=[-1, 1],
        ylim=[-1, 1],
        xlabel="x vals",
        title="header",
    )
    string = fig.get_string()

    ref = """                       header

    1 +---------------------------------------+