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

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]

Previous topic

scitools.avplotter

This Page