scitools.aplotter

aplotter is a Python module for drawing graphs in pure ASCII format. This allows graphs to be included in doc strings (Python programs) or as illustrations in programs in any computer language.

The module offers a function

plot(x, y, draw_axis=True, plot_slope=True, plot_labels=False, dot=’*’,
min_x=None, max_x=None, min_y=None, max_y=None, output=sys.stdout)

where x and y are sequences of x and y data for a curve. Axes are automatically calculated from the x and y data if not min_x, max_x, min_y or max_y are given.

Multiple curves in the plot is not supported.

Here are examples on various plot commands:

>>> from scitools.aplotter import plot
>>> from numpy import linspace, exp, cos, pi
>>> x = linspace(-2, 2, 81)
>>> y = exp(-0.5*x**2)*cos(pi*x)
>>> plot(x, y)
                                        |                                       
                                       -+1                                      
                                     // |\                                     
                                    /   |  \                                    
                                   /    |   \                                   
                                  /     |   \                                   
                                  /     |    \                                  
                                 /      |     \                                 
                                /       |      \                                
                               /        |      \                                
   -------\                    /        |       \                    -------*   
---+-------\-----------------/---------+--------\-----------------//-------+---
   -2        \                /         |        \                /       +2    
              \              /         |         \             //              
                \            /          |         \            /                
                 \         /           |          \         //                 
                   \       /            |           \       /                   
                    \    //             |            \-    //                   
                     ----               -0.63          ---/                     
                                        |                                       
>>> 
>>> plot(x, y, draw_axes=False)
-+1

//

/

/

/ /

/

/

/

——- / ——-* + / // + -2 / / +2

/ //
/ /
/ //
/ /
// - //
—- -0.63 —/
>>> 
>>> # plot symbols (the dot argument) at data points:
>>> plot(x, y, plot_slope=False)
                                        |                                       
                                       *+1                                      
                                     ** |**                                     
                                    *   |  *                                    
                                   *    |   *                                   
                                        |                                       
                                  *     |    *                                  
                                 *      |     *                                 
                                *       |      *                                
                                        |                                       
   ********                    *        |       *                    ********   
---+-------**-----------------*---------+--------*-----------------**-------+---
   -2        *                          |                         *       +2    
              **              *         |         *             **              
                *            *          |         *            *                
                 **         *           |          *         **                 
                   *       *            |           *       *                   
                    *    **             |            **    **                   
                     ****               -0.63          ****                     
                                        |                                       
>>>  
>>> # drop axis labels:
>>> plot(x, y, plot_labels=False)
                                        |                                       
                                       -\                                       
                                     // |\                                     
                                    /   |  \                                    
                                   /    |   \                                   
                                  /     |   \                                   
                                  /     |    \                                  
                                 /      |     \                                 
                                /       |      \                                
                               /        |      \                                
   -------\                    /        |       \                    -------*   
-----------\-----------------/---------+--------\-----------------//-----------
             \                /         |        \                /             
              \              /         |         \             //              
                \            /          |         \            /                
                 \         /           |          \         //                 
                   \       /            |           \       /                   
                    \    //             |            \-    //                   
                     ----               |              ---/                     
                                        |                                       
>>> 
>>> plot(x, y, dot='o', plot_slope=False)
                                        |                                       
                                       o+1                                      
                                     oo |oo                                     
                                    o   |  o                                    
                                   o    |   o                                   
                                        |                                       
                                  o     |    o                                  
                                 o      |     o                                 
                                o       |      o                                
                                        |                                       
   oooooooo                    o        |       o                    oooooooo   
---+-------oo-----------------o---------+--------o-----------------oo-------+---
   -2        o                          |                         o       +2    
              oo              o         |         o             oo              
                o            o          |         o            o                
                 oo         o           |          o         oo                 
                   o       o            |           o       o                   
                    o    oo             |            oo    oo                   
                     oooo               -0.63          oooo                     
                                        |                                       
>>> 
>>> # store plot in a string:
>>> p = plot(x, y, output=str)
>>> print p
                                        |                                       
                                       -+1                                      
                                     // |\                                     
                                    /   |  \                                    
                                   /    |   \                                   
                                  /     |   \                                   
                                  /     |    \                                  
                                 /      |     \                                 
                                /       |      \                                
                               /        |      \                                
   -------\                    /        |       \                    -------*   
---+-------\-----------------/---------+--------\-----------------//-------+---
   -2        \                /         |        \                /       +2    
              \              /         |         \             //              
                \            /          |         \            /                
                 \         /           |          \         //                 
                   \       /            |           \       /                   
                    \    //             |            \-    //                   
                     ----               -0.63          ---/                     
                                        |                                       
class scitools.aplotter.Plotter(**kwargs)[source]

Bases: object

Methods

PlotData
draw_axes(output_buffer, plot_data)
get_coord(val, min, step)
get_symbol_by_slope(slope, default_symbol)
plot_data(xy_seq, output_buffer, plot_data)
plot_double(x_seq, y_seq[, min_x, max_x, ...])
plot_labels(output_buffer, plot_data)
plot_line(start, end, output_buffer, plot_data)
plot_single(seq[, min_x, max_x, min_y, max_y])
class PlotData(x_size, y_size, min_x, max_x, min_y, max_y, x_mod, y_mod)[source]

Bases: object

__class__

alias of type

__delattr__

x.__delattr__(‘name’) <==> del x.name

__dict__ = dict_proxy({'__module__': 'scitools.aplotter', '__repr__': <function __repr__ at 0x87022a8>, '__dict__': <attribute '__dict__' of 'PlotData' objects>, '__weakref__': <attribute '__weakref__' of 'PlotData' objects>, '__doc__': None, '__init__': <function __init__ at 0x8702398>})
__format__()

default object formatter

__getattribute__

x.__getattribute__(‘name’) <==> x.name

__hash__() <==> hash(x)
__init__(x_size, y_size, min_x, max_x, min_y, max_y, x_mod, y_mod)[source]
__module__ = 'scitools.aplotter'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__()[source]
__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__() → int

size of object in memory, in bytes

__str__() <==> str(x)
static __subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

Plotter.__class__

alias of type

Plotter.__delattr__

x.__delattr__(‘name’) <==> del x.name

Plotter.__dict__ = dict_proxy({'plot_data': <function plot_data at 0x8702aa0>, '__module__': 'scitools.aplotter', 'plot_labels': <function plot_labels at 0x8702c08>, 'plot_line': <function plot_line at 0x8702140>, 'draw_axes': <function draw_axes at 0x8702b90>, 'plot_single': <function plot_single at 0x8702de8>, 'plot_double': <function plot_double at 0x8702c80>, 'PlotData': <class 'scitools.aplotter.PlotData'>, 'get_symbol_by_slope': <staticmethod object at 0x57c3910>, '__dict__': <attribute '__dict__' of 'Plotter' objects>, 'get_coord': <staticmethod object at 0x586ffd8>, '__weakref__': <attribute '__weakref__' of 'Plotter' objects>, '__doc__': None, '__init__': <function __init__ at 0x8702320>})
Plotter.__format__()

default object formatter

Plotter.__getattribute__

x.__getattribute__(‘name’) <==> x.name

Plotter.__hash__() <==> hash(x)
Plotter.__init__(**kwargs)[source]
Plotter.__module__ = 'scitools.aplotter'
static Plotter.__new__(S, ...) → a new object with type S, a subtype of T
Plotter.__reduce__()

helper for pickle

Plotter.__reduce_ex__()

helper for pickle

Plotter.__repr__() <==> repr(x)
Plotter.__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

Plotter.__sizeof__() → int

size of object in memory, in bytes

Plotter.__str__() <==> str(x)
static Plotter.__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

Plotter.__weakref__

list of weak references to the object (if defined)

Plotter.draw_axes(output_buffer, plot_data)[source]
static Plotter.get_coord(val, min, step)[source]
static Plotter.get_symbol_by_slope(slope, default_symbol)[source]
Plotter.plot_data(xy_seq, output_buffer, plot_data)[source]
Plotter.plot_double(x_seq, y_seq, min_x=None, max_x=None, min_y=None, max_y=None)[source]
Plotter.plot_labels(output_buffer, plot_data)[source]
Plotter.plot_line(start, end, output_buffer, plot_data)[source]
Plotter.plot_single(seq, min_x=None, max_x=None, min_y=None, max_y=None)[source]
scitools.aplotter.plot(*args, **flags)[source]

This Page