scitools.avplotter

avplotter (“ascii vertical plotter”) is a simple ASCII plotter for curve plots, where the x axis points downward and the y axis is horizontal. The plot is realized by printing it line by line. There are two main applications: 1) very long time series, and 2) plots that would be convenient to have as pure text.

See the documentation of class Plotter for examples of various types of plots.

class scitools.avplotter.Plotter(ymin, ymax, width=68, symbols='*o+x@', vertical_line=0)[source]

ASCII plotter with x axis downwards and y axis horizontal. Can make a plot by writing out new x values line by line in a terminal window or a file. Very suited for long time series.

Example:

>>> a = 0.2
>>> p = Plotter(-1-a, 1+a, width=50)
>>> from math import sin, pi
>>> from numpy import linspace
>>> num_periods = 2
>>> resolution_per_period = 22
>>> tp = linspace(0, num_periods*2*pi,
...               num_periods*resolution_per_period + 1)
>>> for t in tp:
...     y = (1 + a*sin(0.5*t))*sin(t)
...     print 't=%5.2f' % t, p.plot(t, y), '%5.2f' % y
...
t= 0.00                          |                           0.00
t= 0.29                          |     *                     0.29
t= 0.57                          |           *               0.57
t= 0.86                          |                *          0.82
t= 1.14                          |                    *      1.01
t= 1.43                          |                      *    1.12
t= 1.71                          |                       *   1.14
t= 2.00                          |                     *     1.06
t= 2.28                          |                  *        0.89
t= 2.57                          |            *              0.64
t= 2.86                          |      *                    0.34
t= 3.14                          |                           0.00
t= 3.43                   *      |                          -0.34
t= 3.71             *            |                          -0.64
t= 4.00       *                  |                          -0.89
t= 4.28    *                     |                          -1.06
t= 4.57  *                       |                          -1.14
t= 4.86   *                      |                          -1.12
t= 5.14     *                    |                          -1.01
t= 5.43         *                |                          -0.82
t= 5.71              *           |                          -0.57
t= 6.00                    *     |                          -0.29
t= 6.28                          |                          -0.00
t= 6.57                          |     *                     0.27
t= 6.85                          |          *                0.51
t= 7.14                          |             *             0.69
t= 7.43                          |                *          0.81
t= 7.71                          |                 *         0.86
t= 8.00                          |                 *         0.84
t= 8.28                          |               *           0.76
t= 8.57                          |            *              0.62
t= 8.85                          |        *                  0.44
t= 9.14                          |    *                      0.23
t= 9.42                          |                           0.00
t= 9.71                     *    |                          -0.23
t=10.00                 *        |                          -0.44
t=10.28             *            |                          -0.62
t=10.57          *               |                          -0.76
t=10.85        *                 |                          -0.84
t=11.14        *                 |                          -0.86
t=11.42         *                |                          -0.81
t=11.71            *             |                          -0.69
t=12.00               *          |                          -0.51
t=12.28                    *     |                          -0.27
t=12.57                          |                          -0.00

Here is a one-dimensional random walk example:

import time, numpy as np
p = Plotter(-1, 1, width=75)
np.random.seed(10)
y = 0
while True:
    random_step = 1 if np.random.random() > 0.5 else -1
    y = y + 0.05*random_step
    if y < -1:
        print 'HOME!!!!!!!!!'
        break
    print p.plot(0, y)
    try:
        time.sleep(0.1)
    except KeyboardInterrupt:
        print 'Interrupted by Ctrl-C'
        break

One can easily plot two or more curves side by side. Here we plot two curves (sine and cosine), each with a width of 25 characters:

p_sin = Plotter(-1, 1, width=25, symbols='s')
p_cos = Plotter(-1, 1, width=25, symbols='c')
from math import sin, cos, pi
from numpy import linspace
tp = linspace(0, 6*pi, 6*8+1)
for t in tp:
    print p_sin.plot(t, sin(t)), p_cos.plot(t, cos(t))

The output reads:

             |                          |           c
             |   s                      |          c
             |       s                  |       c
             |          s               |   c
             |           s              |
             |          s          c    |
             |       s         c        |
             |   s          c           |
             |             c            |
        s    |              c           |
    s        |                 c        |
 s           |                     c    |
s            |                         c|
 s           |                          |   c
    s        |                          |       c
        s    |                          |          c
            s|                          |           c
             |   s                      |          c
             |       s                  |       c
             |          s               |   c
             |           s              |
             |          s          c    |
             |       s         c        |
             |   s          c           |
             |             c            |
        s    |              c           |
    s        |                 c        |
 s           |                     c    |
s            |                         c|
 s           |                          |   c
    s        |                          |       c
        s    |                          |          c
            s|                          |           c
             |   s                      |          c
             |       s                  |       c
             |          s               |   c
             |           s              |
             |          s          c    |
             |       s         c        |
             |   s          c           |
             |             c            |
        s    |              c           |
    s        |                 c        |
 s           |                     c    |
s            |                         c|
 s           |                          |   c
    s        |                          |       c
        s    |                          |          c
            s|                          |           c

Alternatively, two curves (here sine and cosine) can be plotted in the same coordinate system:

p = Plotter(-1, 1, width=50, symbols='sc')
from math import sin, cos, pi
from numpy import linspace
tp = linspace(0, 6*pi, 6*8+1)
for t in tp:
    print p.plot(t, sin(t), cos(t))

The output from this code becomes:

                         |                        c
                         |         s            c
                         |                 c
                         |         c            s
                         |                        s
               c         |                      s
       c                 |                 s
  c                      |         s
c                        |
  c            s         |
       c                 |
  s            c         |
s                        |
  s                      |         c
       s                 |                 c
               s         |                      c
                         |                        c
                         |         s            c
                         |                 c
                         |         c            s
                         |                        s
               c         |                      s
       c                 |                 s
  c                      |         s
c                        |
  c            s         |
       c                 |
  s            c         |
s                        |
  s                      |         c
       s                 |                 c
               s         |                      c
                         |                        c
                         |         s            c
                         |                 c
                         |         c            s
                         |                        s
               c         |                      s
       c                 |                 s
  c                      |         s
c                        |
  c            s         |
       c                 |
  s            c         |
s                        |
  s                      |         c
       s                 |                 c
               s         |                      c
                         |                        c

Methods

plot(x, *y, **kwargs) Return next line in plot, given x and some y values.
__init__(ymin, ymax, width=68, symbols='*o+x@', vertical_line=0)[source]

Create a line by line plotter with the x axis pointing downward. The ymin and ymax variables define the extent of the y axis. The width parameter is the number of characters used for the y domain (axis). The symbols used for curves are given by the symbols string (first symbol, by default is *, next is o). The vertical_line parameter specifies for which y value where the x axis is drawn (y=0 by default).

__module__ = 'scitools.avplotter'
plot(x, *y, **kwargs)[source]

Return next line in plot, given x and some y values.

Supported kwargs: print_out_of_range_value: if True, print the value if it is out of range.

scitools.avplotter.plot(*args, **kwargs)[source]

Easyviz-style plot command. args holds x1, y1, x2, y2, ...:

plot(t, u1, t, u2, axis=[0, 10, -1, 1])

No other keyword arguments has any effect.

scitools.avplotter.run_random_walk()[source]
scitools.avplotter.test_2_curves_v1()[source]
scitools.avplotter.test_2_curves_v2()[source]
scitools.avplotter.test_random_walk()[source]
scitools.avplotter.test_sin()[source]

This Page