\input texinfo   @c -*-texinfo-*-
@setfilename pychart.info
@settitle PyChart Reference Manual
@exampleindent 0
@macro chart
PyChart
@end macro
@setchapternewpage off
@titlepage
@title PyChart Reference Manual
@subtitle Version 1.25
@subtitle Oct 02, 2002
@author Yasushi Saito
@end titlepage

@contents
@syncodeindex pg cp
@syncodeindex vr cp
@syncodeindex fn cp

@node Top, Copying, (dir), (dir)


@macro shadow
Parameter @var{shadow}, if none, draws a drop-shadow.  It should be a
tuple of three values, (@var{x_off}, @var{y_off}, @var{fill}). 
@end macro

@menu
* Copying::                     Your rights.
* Introduction::                Overview of pychart, along with examples.
* Options::                     Controlling pychart via env variable and cmdline.
* Anatomy::                     Overview of chart components
* Attributes::                  Setting and reading object attributes.        
* Unit::                        Unit of length and scaling chart.        
* chart_data::                  Reading CSV files and transforming data.
* area::                        
* bar_plot::                    Drawing a bunch of bars.
* line_plot::                   Line and scatter plots.
* range_plot::                  Range-fill plots.
* pie_plot::                    Pie plots to show shares of things.
* legend::                      A small box that describes lines or bars. 
* line_style::                  Specifying width, color, and dash style of lines.
* color::                       Red, green, yellow, etc.
* fill_style::                  Specfiying background patterns
* font::                        Changing font name, size, and angle 
* text_box::                    Drawing "callout box" with texts and arrows
* arrow::                       Drawing arrows.
* Tricks::                      A few tricks you can do using internal modules.
* Index::                       

@detailmenu
 --- The Detailed Node Listing ---

Area

* coord::                       Specifying the coordinate system. Linear, log, etc.
* axis::                        Displaying X and Y axes.

Line and scatter plots

* tick_mark::                   Drawing a funny symbol drawn at each sample point.
* error_bar::                   Drawing error bars

Tricks

* canvas::                      Drawing arbitrary objects on canvas
* Clipping::                    
* Redirecting output::          Drawing multiple graphs.                 

@end detailmenu
@end menu

@node Copying, Introduction, Top, Top
@chapter Copying

		    GNU GENERAL PUBLIC LICENSE
		       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS

	    How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 19yy  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) 19yy name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Library General
Public License instead of this License.

@node Introduction, Options, Copying, Top
@chapter Introduction

This document describes @chart{} Version 1.25.
@chart{} is a Python library for creating ``professional''
quality charts. It produces line plots, bar plots, range-fill plots, and
pie charts in Postscript, PDF, PNG, or SVG.  The following sections
illustrate some uses of Pychart.

@section Line plot

%ilinetest

This example draws a simple line plot. Below is the source code needed to
produce this chart.

@noindent
@strong{linetest.py}:
%-linetest.py

To produce a Postscript chart, just feed the file to Python.

@example
% python linetest.py >linetest.eps
@end example

Or, to produce a PDF chart, run python like below
@footnote{To handle command-line options such as @samp{--format=pdf},
you need to put @samp{theme.get_options()} in the beginning of your file.
@xref{Options}.}:

@example
% python linetest.py --format=pdf >linetest.pdf
@end example

@chart{} also supports PNG, SVG, and interactive X11 display. 
For more information about output control, @ref{Options}.

Every pychart program starts with @code{from pychart import *} to import
classes and objects provided by @chart{}.  Each chart is represented by
an @code{area} object, which defines the size , the coordinate system
(linear, log, etc), and plots to be drawn in the chart. The final line
of the program should end with @code{area.draw()}, which draws all the
components of the chart to the standard output.

@section Bar plot

%ibartestv

Above example is a little more complicated chart. the below program
generates this chart.

%-bartestv.py

@node Options, Anatomy, Introduction, Top
@chapter PyChart Options
@vindex PYCHART_OPTIONS
@cindex command-line options
@cindex redirecting output

The behavior of @chart{} can be changed in three ways, via environment
variable @samp{PYCHART_OPTIONS}, via command-line options, and by
setting variables in module @samp{theme} directly.

@section PYCHART_OPTIONS 

The value of the environment variable @samp{PYCHART_OPTIONS}, if any,
should be a sequence of @samp{var=val}, separated by space.  Below is an
example, which tells @chart{} to write to file @file{foo.pdf} and use
Times-Roman as the default font.

@example
% PYCHART_OPTIONS="output=foo.pdf font-family=Times"
% export PYCHART_OPTIONS
@end example

The summary of attributes that can be set via @samp{PYCHART_OPTIONS}
follows.

@table @code
@item output=@var{filename}

@cindex output file name
@cindex file name
Sets the output file name. Without this option, @chart{} sends code
to the standard output.

@item @code{format=}@var{format}
@cindex Postscript
@cindex PDF
@cindex PNG
@cindex SVG
@cindex X11
 
This option sets the encoding of the data produced by @chart{}. 
@var{Format} must be one of the following:

@table @asis
@item @code{ps}
Encapsulated Postscript. This is the default.  

@item @code{pdf}
Adobe Page Description Format, or PDF.  

@item @code{pdf-uncompressed}
PDF without compression.
This option should be used for debugging purpose only.  

@item @code{png}
PNG graphics.  You need to have ghostscript (@code{gs}) installed to use
this option, because @chart{} internally calls ghostscript to convert ps
to png.

@item @code{svg}
Scalable vector graphics.  

@item @code{x11}
Interactive display on an X window. You need to have ghostscript
installed to use this option.  
@cindex ghostscript
@end table

Without this option, @chart{} guesses the format from the file name
(@samp{output=}@var{filename}).  Failing to guess, @chart{} will dump
encapsulated Postscript.

@item font-family=@var{name}
@item font-size=@var{size}
@cindex font

This option sets the default font family and size of texts.  The default
is Helvetica at 9 points.
@xref{font}.

@item @code{line-width=}@var{x}
@cindex line width
Set the default line width, in points. The default value is
0.4. @xref{line_style}.

@item @code{scale=}@var{n}
@cindex scaling charts
Set the scaling factor (i.e., @samp{scaling.scale_factor}).  The default
value is 1.0. @xref{Unit}.

@item @code{color=[yes|no]}
@cindex colorized charts

If yes, @chart{} colorizes default object attributes.  In particular:

@itemize @bullet
@item The standard color list (@code{colors.standards}) will include all 
the colors listed in X's RGB file. So you can use something like
"@samp{color.slate_blue}"@footnote{In fact, you can use these color names
in gray-scale mode as well. They will appear in some gray color though.}

@item The standard fill style list (@code{fill_style.standards}) will
be colorized.  Thus, if you create a bar plot without explicitly
specifying its fill style, you will see colored bars on the canvas.

@item The standard line style list (@code{line_style.standards}) will be colorized.
@end itemize

If the value is @samp{no}, @chart{} uses gray-scale for these objects.
The default value of this attribute is @samp{no}.

@item @code{debug-level=@var{N}}
@cindex debug level

This option controls the verbosity of messages from @chart{}. The
default value is 1, meaning that @chart{} only displays error
messages. The larger the value, the more verbose @chart{} becomes.
@end table

@section Command-line options
@cindex command line options

The options can also be set from the command line. To do this, the program
that imports Pychart must call @samp{theme.get_options} on
start up, because Pychart itself is just a library.

@defun theme.get_options ARGV = sys.argv[1:]
%d theme.get_options
@end defun

@section Setting variables manually
@pindex theme

You can change @chart{}'s behaviour by setting variables in the module
@samp{theme} directly. After setting values, you @emph{must} call
@samp{theme.reinitialize()} to reflect the changes in @chart{}.

@example
theme.scale_factor = 3
theme.reinitialize()
@end example

The above example has the same effect as setting
``@samp{PYCHART_OPTIONS="scale=3"}''. 

@defvar theme.use_color
Setting this variable to 1 has the same effect as 
setting @samp{color=yes} in PYCHART_OPTIONS.
@end defvar

@defvar theme.output_format 
Equivalent to @samp{format=} in PYCHART_OPTIONS.
This option is meaningful only before calling area.draw()
(@pxref{area}).
@end defvar

@defvar theme.output_file
Equivalent to @samp{output=} in PYCHART_OPTIONS.
This option is meaningful only before calling area.draw()
(@pxref{area}).
If you want to produce multiple charts from a single Python source file,
use @samp{canvas.init(FILE)}. (@pxref{Redirecting output}).
@end defvar

@defvar theme.default_font_family
Equivalent to @samp{font-family=} in PYCHART_OPTIONS.
@end defvar

@defvar theme.default_font_size
Equivalent to @samp{font-size=} in PYCHART_OPTIONS.
@end defvar

@defvar theme.default_line_height
Equivalent to @samp{line-height=} in PYCHART_OPTIONS.
@end defvar


@node Anatomy, Attributes, Options, Top
@chapter Anatomy of a chart

A chart comprises a set of @dfn{components}. Each component belongs to a
certain class, from which an instance tailored for a particular chart is
generated. The standard set of component classes follow:

@vtable @strong
@item area.T
The @code{area} class defines the size, the location, and the coordinate
system (linear, logarithmic, etc) of a chart (@pxref{area}).  It also
contains axes, plots, and legends, as described below.  At least one
Area must be created in any chart.

@item axis.X
@item axis.Y
The axis class defines the look of an axis. You can specify, for
example, the interval and the style of tick marks and grid lines
(@pxref{axis}). @chart{} provides two types of axes, @code{axis.X} and
@code{axis.Y}, corresponding to horizontal and vertical axes.

@item plot.T
The @code{plot} class actually draws a chart. Several subclasses of
plots are provided by @chart{}, including line plots
(@pxref{line_plot}), range-fill plots (@pxref{range_plot}), bar plots
(@pxref{bar_plot}), and pie plots (@pxref{pie_plot}). You can draw
multiple plots in a single chart, and most of the times you can even mix
different types of plots, e.g., line plots and bar plots.

@item legend.T
The @code{legend} class is an optional rectangular box that describes
what each plot means (@pxref{legend}). 

@item text_box.T
The @code{text_box} is an optional rectangular box that contains
arbitrary text.  It can also contain arrows (@pxref{text_box}).

@item canvas.T
The @code{canvas} is a "virtual paper" that defines graph-drawing
primitives, such as lines, rectangles, and texts. One canvas corresponds
to one output file. Canvas is used by other components in the graph and
is usually not manipulated by users directly.  It's handy, however, if
you want to draw a line/circle/text/etc, directly on the Postscript or
PDF file. @xref{canvas}.
@end vtable

@node Attributes, Unit, Anatomy, Top
@chapter Attributes
@cindex attribute

The look and feel of a component of a chart (@pxref{Anatomy}) are
defined by a collection of @dfn{attributes}.  For example, Axis
(@pxref{axis}) includes an integer @code{tic_len} attribute that defines
the length of "tick" lines drawn perpendicular to the axis. It also has
an integer @code{tic_interval} attribute that defines the separation
between tick lines. (For the full list of Axis's attributes,
@xref{axis}.)

Attributes are usually specified by named arguments while creating a
component:

@example
ax = axis.X(tic_len = 3, tic_interval = 50)
@end example

@noindent
Attributes can also be changed after a component is created, but before
@code{area.draw()}, the main drawing procedure (@pxref{area}), is called. 
The below example has the same effect as the above.
@pindex area.draw

@example
ax = axis.X()
ax.tic_len = 3
ax.tic_interval = 50
@end example

@cindex default attribute values
@cindex attribute, default values

Each attribute has a default value that supposedly gives you a standard
look to the chart. You can change the default values through
@code{chart_object} module. For example, the below example has the same
effect as the above, except that all X axes created in the
future will have the new default values. 

@findex chart_object.set_defaults
@findex set_defaults

@example
chart_object.set_defaults(axis.X, tic_len=3, tic_interval=50)
ax = axis.X()
@end example

@node Unit, chart_data, Attributes, Top
@chapter Unit of length and the coordinate System

@cindex unit of length
@cindex Postscript
@cindex points

In @chart{}, the X axis grows to the right, and the Y axis grows up
(the same as Postscript, but different from X and Windows).

Lengths are measured by ``Postscript points'', which coincides with
@TeX{} points. One point is equal to 1/72 inch.  Several variables and
functions are provided to manipulate lengths:

@defvar theme.scale_factor
Defines chart magnification. The default value is 1.0, meaning that
one point actually means one Postscript point.  Setting this value to
3.0, for example, makes @chart{} draw everything three times larger.
@end defvar
@vindex scale_factor

@defun area.x_pos XVAL
Converts X @var{XVAL} to a coordinate on the canvas (@pxref{canvas}).
@end defun

@defun area.y_pos YVAL
Converts Y @var{YVAL} to a coordinate on the canvas (@pxref{canvas}).
@end defun

@example
ar = area.T(loc=(50, 50), size=(100, 100), 
            xrange=(0,200), yrange=(0, 1000))
px = ar.x_pos(50)
py = ar.y_pos(100)
@end example

@noindent
In the above example, the chart is drawn on the area defined by
rectangle @math{(50, 50) - (150, 150)}.  The point (@code{px, py}) will
be at @math{(75, 60)}, which is the screen location at which the point
@math{(50, 100)} would be drawn (i.e., @math{50 + 100 * 50/200 = 75},
@math{50 + 100 * 100 / 1000 = 60}).

@cindex coordinate
@cindex X axis
@cindex Y axis
@cindex axis

@node chart_data, area, Unit, Top
@chapter Input data
@cindex data
@cindex samples

The basic function of @chart{} is to draw samples in a variety of ways.
Samples are simply a sequence of sequences, where @emph{sequence} is a
Python term that stands for either a tuple (comma-separated numbers or
strings enclosed in parenthesis) or a list (comma-separated numbers or
strings enclosed in square brackets). Data are given to plots through
the "@code{data}" attribute:

@example
l = line_plot.T(data=[(10,20), (11,38), (12,29)], xcol=0, ycol=1)
@end example

@noindent
In the above example, three sample points will be drawn along with line
segments that connect them: @math{(10, 20) - (11, 38) - (12, 29)}.
Attribute @code{xcol} tells the locations of X values within data (the
first column of each sample in @code{data}), and @code{ycol} similarly
tell the locations of Y values (the last column of each sample in
@code{data}).  A sample point can contain None, in which case 
it is ignored. 

@example
data = [(10, 20, 21), (11, 38, 22), (13, None, 15), (12, 29, 30)]
l1 = line_plot.T(data=data, xcol=0, ycol=1)
l2 = line_plot.T(data=data, xcol=0, ycol=2)
@end example

@noindent
The above example is equivalent to:

@example
l1 = line_plot.T(data=[(10, 20), (11, 38), (12, 29)], xcol=0, ycol=1)
l2 = line_plot.T(data=[(10, 21), (11, 22), (13, 15), (12, 30)], xcol=0, ycol=1)
@end example


Module @code{chart_data} provides several functions for generating or
reading sample points.

@vindex xcol
@vindex ycol
@pindex data
@cindex csv

@defun chart_data.read_csv FILE, DELIM = ','
@findex scanf
%dchart_data.read_csv
@end defun

@defun chart_data.fread_csv FP, DELIM=','
%dchart_data.fread_csv
@end defun

@defun chart_data.read_str DELIM, LINES
%dchart_data.read_str
@end defun

@defun chart_data.func F, FROM, TO, STEP
%dchart_data.func
@end defun

@defun chart_data.filter F, DATA
@findex Filter
%dchart_data.filter
@end defun

@defun chart_data.extract_rows DATA, ROWS...
%dchart_data.extract_rows
@end defun

@defun chart_data.extract_columns DATA, COLS...
%dchart_data.extract_columns
@end defun

@defun chart_data.transform FUNC, DATA
%dchart_data.transform
@end defun

@defun chart_data.moving_average DATA, XCOL, YCOL, WIDTH
@cindex average
@cindex mean
%dchart_data.moving_average
@end defun

@defun chart_data.median DATA, COL=1
@cindex median
%dchart_data.median
@end defun


@node area, bar_plot, chart_data, Top
@chapter Area
@vindex area

Class @code{area.T} defines the location and size of a chart. It also
defines the coordinate system (linear, log, or enumeration) of the X and
Y axes. The X coordinate system is defined using attribute
@samp{x_coord_system} attribute, which takes one of three strings:
"linear", "log", "category". For the first two, the minimum and maximum
displayable values in the area are either given explicitly via
@samp{x_range}, or is computed automatically from the plots when it is
omitted. When @samp{x_coord_system == "category"}, then the X axis takes
discrete values, taken from @samp{x_category_col}'th column of samples
@samp{x_category_data}. The the Y coordinate system can also be
specified using the combination of attributes @samp{y_coord_system},
@samp{y_category_col}, and @samp{y_category_data}.

@cindex logarithmic scale 
@cindex category axis

@example
ar = area.T(x_coord_system = "log", x_range = (10, None), ...)
@end example

In the above example, an X axis is drawn with a logarithmic scale. The
minimum value will be 10, and the maximum value will be computed from
the values given to plots. The below is an example of a category
coordinate system.

@example
samples = [("apple", 10), ("orange", 30), ("blueberry", 20)], 
ar = area.T(x_coord_system = "category", 
            x_category_data = samples, x_category_col = 0)        
ar.add_plot(bar_plot.T(data = samples, ...))
@end example

%%area.T

Objects of @code{area.T} also define several methods:

@defun add_plot PLOT, ...
Add plots. @code{plot} must be a plot. @xref{line_plot}, @ref{bar_plot},
@ref{pie_plot}, @ref{range_plot}.
@end defun

@defun area.draw
Draw plots, axes, and the legend. This procedure must be called at the
end of every @chart{} application.
@end defun

@defun area.x_pos XVAL
Converts X @var{XVAL} to a coordinate on the canvas (@pxref{canvas}).
@end defun
@cindex Postscript

@defun area.y_pos YVAL
Converts Y @var{YVAL} to a coordinate on the canvas (@pxref{canvas}).
@end defun

@menu
* coord::                       Specifying the coordinate system. Linear, log, etc.
* axis::                        Displaying X and Y axes.
@end menu

@node coord, axis, area, area
@section Specifying the coordinate system
@cindex coord
@cindex x_coord
@cindex y_coord
@cindex coordinate system

Attributes @samp{x_coord} and @samp{y_coord} specifies the coordinate
systems for the area's X and Y axes. The values of these attributes
must of type @samp{coord}. @chart{} provides three popular subclasses
of @samp{coord}.  Both @samp{x_coord} and @samp{y_coord} defaults to
@samp{linear_coord.T()}.

@vtable @samp
@item linear_coord.T
This class makes the coordinate system linear. 

@example
ar = area.T(x_coord = linear_coord.T(), y_coord = linear_coord.T(), ...)
@end example

@item log_coord.T
This class displays a logarithmic coordinate system.

@item category_coord.T
This class defines a ``categorical'' coordinate system, in which the
axis only takes discrete values. This class takes two constructors:
data (@pxref{chart_data}) and column from which the axis values are
extracted from the data. See the following example:

%-categbar.py

The output will look like the below:

%icategbar

@end vtable

@cindex zap marks

You can create fancier coordinate systems by subtyping @samp{coord.T}.
The below example shows how you can create a chart with ``zap'' marks.


%izaptest

A @samp{coord.T} object must implement three methods: 

@deffn Method get_data_range DMIN DMAX INTERVAL
This method should compute the minimum and maximum values that are to be
displayed on the canvas. DMIN, DMAX are the minimum and maximum values found
in the sample data given to the plots. INTERVAL is the value of 
the area's ``tic_interval'' attribute (@pxref{area}), or None if the
attribute is ommitted by the user. This method should return tuple
(MIN, MAX, INTERVAL), where MIN, MAX are the minimum and maximum values
to be displayed, and INTERVAL is the interval with which label and tick lines
are drawn.
@end deffn

@deffn Method get_canvas_pos SELF SIZE VAL RANGE
This method converts a data value (VAL) to canvas location.
SELF is the coordinate object itself, SIZE is the size of the 
axis, either X or Y, and RANGE is the minimum and maximum sample
values obtained by calling @samp{SELF.get_data_range}. 
@end deffn

@deffn Method get_tics SELF RANGE INTERVAL
This method should return the list of values (not canvas locations) at which
labels and ``tick'' lines are drawn. Parameters RANGE and INTERVAL are the
values returned by get_data_range.
@end deffn

For example, the above chart is generated by the following script:

%-zaptest.py

@node axis,  , coord, area
@section Axes
@cindex X axis
@cindex Y axis
@cindex axis

Module @samp{axis} defines the look of an axis as well as grid
lines. Two classes, @samp{axis.X} and @samp{axis.Y}, are provided by
this module.

@vtable @asis
@item axis.X

%%axis.X

@item axis.Y

%%axis.Y
@end vtable

@node bar_plot, line_plot, area, Top
@chapter Bar Plots
@cindex bar plot

%%bar_plot.T

%-bartest, Sample bar charts
%-bartestv, Vertical bar chart

@node line_plot, range_plot, bar_plot, Top
@chapter Line and scatter plots
@cindex line plot
@cindex scatter plot

%%line_plot.T

%-linetest3, Sample line plot

@cindex Scatter plot

Scatter plots can be created by setting the @code{line_style} attribute
to @code{None}. See the next example.

%-scattertest, Sample scatter plot

@menu
* tick_mark::                   Drawing a funny symbol drawn at each sample point.
* error_bar::                   Drawing error bars
@end menu

@node tick_mark, error_bar, line_plot, line_plot
@section Tick marks
@cindex tick mark

Tick marks are used in conjunction with line plots (@pxref{line_plot})
to show where sample points are. Tick marks derive from a single base class, 
@samp{tick_mark.Base}:

%%tick_mark.Base

Several types of tick marks are offered by @chart{} as subclasses of
@samp{tick_mark.Base}.  They include: tick_mark.Circle,
tick_mark.Square, tick_mark.Triangle, tick_mark.DownTriangle,
tick_mark.X, tick_mark.Plus, tick_mark.Diamond, tick_mark.Star,
tick_mark.Null.  Specific instance of these classes are also defined for
your convenience.  Below is the list of such standard tick marks.  They
are referred to by as "@code{tick_mark.}@var{name}", where @var{name} is
the labels below them.

%itickmarks

@node error_bar,  , tick_mark, line_plot
@section Error Bars

@cindex error bar
@table @asis
@item error_bar.error_bar1
%%error_bar.error_bar1

@item error_bar.error_bar2
%%error_bar.error_bar2

@item error_bar.error_bar3
%%error_bar.error_bar3

@item error_bar.error_bar4
%%error_bar.error_bar4

@end table

%ierrorbars

@node range_plot, pie_plot, line_plot, Top
@chapter Range Plots
@cindex range plot

%%range_plot.T

%#rangetest, Sample range plot

@node pie_plot, legend, range_plot, Top
@chapter Pie Plots
@cindex pie plot

%%pie_plot.T

%-pietest, Sample pie chart

@node legend, line_style, pie_plot, Top
@chapter Legends
@cindex legend

%%legend.T

The default location of a legend is the bottom-right end of the chart.

@node line_style, color, legend, Top
@chapter Line Styles

%%line_style.T

%ilinestyles

Standard line styles. These styles are referred to by names
@code{line_style.}@var{name}, where @var{name} is the labels below them.

@node color, fill_style, line_style, Top
@chapter Colors

%%color.T

@cindex colors
@pindex rgb.txt
You can use all the colors defined in X rgb.txt (usually at
@file{/usr/X11R6/lib/X11/rgb.txt}). The below shows some of the standard
colors defined in the module.  They are refereed to by the names
@code{color.}@var{name} (e.g., @code{color.gray1}).

%icolors

@node fill_style, font, color, Top
@chapter Fill Styles

The class @code{fill_style.T} determines the color and the pattern of the
background of a region. 

%%fill_style.T

The actual background patterns are offered by subclasses of
@code{fill_style.T}:

@deffn Class fill_style.Plain
%dfill_style.Plain
@end deffn

@deffn Class fill_style.Diag
%dfill_style.Diag
@end deffn

@deffn Class fill_style.Rdiag
Fills the region with diagonal lines, but tilted in the opposite
direction from @samp{fill_style.Diag}.
@end deffn

@deffn Class fill_style.Vert
Fills the region with vertical lines.
@end deffn

@deffn Class fill_style.Horiz
Fills the region with horizontal lines.
@end deffn

@deffn Class fill_style.Stitch
Fills the region with horizontal and vertical lines.
@end deffn

@deffn Class fill_style.Wave
Fills the region with horizontal wavy lines.
@end deffn

@deffn Class fill_style.Vwave
Fills the region with vertical wavy lines.
@end deffn

@deffn Class fill_style.Lines
Fills the region with a series of short line segments.
@end deffn

The below picture shows the standard set of fill styles. They are named
like @code{fill_style.}@var{name}, where @var{name} are the labels shown
in the picture.

%ifillstyles

Just for your information, the "rdiag3" style shown in the picture can
be created manually by the following code:

@example
rdiag3 = fill_style.Rdiag(line_style=line_style.T(width=3, color=color.gray5),
                          line_interval=6)    
@end example

@node font, text_box, fill_style, Top
@chapter Drawing texts
@cindex text
@cindex font
@cindex canvas.show

You can display text strings in chart as a part of axis labels, plot
labels, legends, etc. You can also display an arbitrary text in an
arbitrary location using annotations (@pxref{text_box}) or
@samp{canvas.show} function (@pxref{canvas}).

Text strings may contain escape characters that control its
appearance.  The escape sequences all start with the letter
``@samp{/}''. Thus, to display ``@samp{/}'' itself, you must write
``@samp{//}''.

@cindex /
@cindex text
@cindex justification (text)
@cindex alignment (text)

@multitable @columnfractions 0.15 0.85
@item @strong{Sequence} @tab @strong{Meaning}
@item @code{/a}@var{dd}
@tab 
Specifies the angle the text is drawn.  Parameter @var{dd} is a number
between -360 to 360.  Value 0 means left-to-right text, 90 means
bottom-to-up, etc.

If you want to print numbers right after an angle specification, put
@code{@{@}} between the angle and the number. For example, the below
code shows string "@code{"100"}" at 60-degree angle.

@example
"/a60@{@}100"
@end example

@item @code{/h}@var{A}
@tab
Specifies horizontal alignment of the text.  @var{A} is one of
"@code{L}" (left alignment), "@code{R}" (right alignment), "@code{C}"
(center alignment).

@item @code{/v}@var{A}
@tab
Specifies vertical alignment of the text.  @var{A} is one of "@code{B}"
(bottom), "@code{T}" (top), "@code{M}" (middle).

@item @code{/T} @tab Switch to Times font family. 
@item @code{/H} @tab Switch to Helvetica font family. 
@item @code{/C} @tab Switch to Courier font family. 
@item @code{/B} @tab Switch to Bookman-Demi font family. 
@item @code{/A} @tab Switch to AvantGarde-Book font family. 
@item @code{/P} @tab Switch to Palatino font family.
@item @code{/S} @tab Switch to Symbol font family.
@item @code{/F@{@var{family}@}} @tab Switch to @var{family} font family.
The below example draws string "Funny" using ZapfDingbat font
(which produces some meaningless output).

@example
canvas.show(100, 200, "/F@{ZapfDingbat@}Funny")
@end example

The list of available fonts are the following:

@example
Bookman-Demi Bookman-Light Courier AvantGarde-Book AvantGarde-Demi
Helvetica Helvetica-Narrow Palatino NewCenturySchlbk Times
Symbol ZapfChancery-MediumItalic ZapfChancery-Medium-Italic ZapfDingbats
@end example

@item @code{/b} @tab Switch to bold typeface.
@item @code{/i} @tab Switch to italic typeface.
@item @code{/o} @tab Switch to oblique typeface.
@item @code{/}@var{dd} @tab Set font size to @var{dd} points.

@example
"/20@{@}2001 space odyssey!"
@end example

@item @samp{/c}@var{dd} @tab Set gray-scale to 0.@var{dd}. 
Gray-scale of 0 means black, 1 means white.

@item @samp{//}, @samp{/@{}, @samp{/@}} @tab Display `/', `@}', or `@{'.
@item @samp{@{ ... @}} @tab Limit the scope of escape sequences. For example, 
@samp{"@{/10@{/20Big text@} and small text@}"} 
will display @samp{"Big Text"} using
20-point font, and @samp{"and small text"} using 10-point font.
@item @samp{\n} @tab Break the line.
@end multitable

@strong{Restriction}: @samp{/h}, @samp{/v}, and @samp{/a} @emph{must}
appear in the beginning of a string.

@pindex font
The @code{font} module defines several procedures and variables for
manipulating fonts:

@defun font.quotemeta TEXT
%dfont.quotemeta
@end defun

@defun font.text_height TEXT
Return the height of the text in points. 
@end defun

@defun font.text_width TEXT
Return the width of the text in points.
@end defun

@defun font.get_dimension TEXT
Return tuple (xmin, xmax, ymin, ymax)
@end defun

@defvar theme.default_family
Default font family (Helvetica).
@end defvar

@defvar theme.default_font_size
Default font size (9). 
@end defvar

@defvar theme.default_halign
Default horizontal alignment (h)
@end defvar

@defvar theme.default_valign
Default vertical alignment (b)
@end defvar

@defvar theme.default_angle
Default angle (0)
@end defvar

%ifonttest

%-fonttest.py

@node text_box, arrow, font, Top
@chapter Annotation
@cindex arrow
@cindex annotation

%%text_box.T

@pindex text_box
In addition to the above attributes, it provides the following methods.

@defun add_arrow TIP, TAIL=None, ARROW=arrow.default

This method adds a straight arrow that points to @var{TIPLOC}, which is
a tuple of integers. @var{TAIL} specifies the starting point of the
arrow. It is either None or a string consisting of the following
letters: 'l', 'c', 'r', 't', 'm,', and 'b'.  Letters 'l', 'c', or 'r'
means to start the arrow from the left, center, or right of the text
box, respectively. Letters 't', 'm', or 'b' means to start the arrow
from the top, middle or bottom of the text box.  For example, when
@samp{tail = 'tc'} then arrow is drawn from top-center point of the text
box. ARROW specifies the style of the arrow. @xref{arrow}.
@end defun

%iannotations

%-annotations.py

@node arrow, Tricks, text_box, Top
@chapter Arrows

Arrow is an optional component of a chart that draws line segments with
an arrowhead. To draw an arrow, one creates an arrow.T object, and calls
its "draw" method usually after area.draw() is called (otherwise, area.draw()
may overwrite the arrow). For example, the below code draws an arrow
from (10,10) to (20,30).

@example
ar = area.T(...)
a = arrow.T(head_style = 1)
ar.draw()
a.draw([(10,10), (20,30)])
@end example

%%arrow.T

An arrow object exports a single public method, @samp{draw}.

@deffn Method draw SELF POINTS
%darrow.T.draw
@end deffn

%iarrows


@node Tricks, Index, arrow, Top
@chapter Tricks

@menu
* canvas::                      Drawing arbitrary objects on canvas
* Clipping::                    
* Redirecting output::          Drawing multiple graphs.                 
@end menu

@node canvas, Clipping, Tricks, Tricks
@section Drawing arbitrary objects on canvas

The @samp{canvas} object, used internally by @chart{}, can be invoked
manually if you desire so.

@defun canvas.line LINESTYLE, X1, Y1, X2, Y2

@example
# draw a line segment from (10,20) to (100, 200)
canvas.line(line_style.blackdash1, 10, 20, 100, 200)    
@end example
@cindex line
@end defun

@defun canvas.polygon LINESTYLE, FILLSTYLE, [(X1,Y1), ..., (Xn, Yn)]

Draw a polygon with LINESTYLE (@pxref{line_style}), fill with FILLSTYLE
(@pxref{fill_style}), and the edges POINTS. POINTS is a list of
corrdinates, e.g., ((10,10), (15,5), (20,8)). SHADOW is either None or a
tuple (XDELTA, YDELTA, SHADOWSTYLE). If non-null, a shadow of
SHADOWSTYLE (@pxref{fill_style})is drawn beneath the polygon at the
offset of (XDELTA, YDELTA).  @var{LINESTYLE} can be None, in which case
no perimeter lines are drawn.  FILLSTYLE (@pxref{fill_style}) can also be
None, in which the internal of the polygon are left undrawn.

@example
canvas.polygon(line_style.default, fill_style.default, 
               [(10, 20), (100, 200), (300,300)])
@end example
@cindex polygon
@end defun

@defun canvas.rectangle LINESTYLE, FILLSTYLE, X1, Y1, X2, Y2, SHADOW=None

@shadow

@example
canvas.rectangle(line_style.default, fill_style.default, 
                 10, 20, 300, 300)
@end example
@cindex rectangle
@end defun

@defun canvas.ellipsis LINESTYLE, FILLSTYLE, X, Y, RADIUS, Y-ELONGATION=1, START=0, END=360, SHADOW=None

The start and end angles are specified in degrees; i.e., between 0 and
360.
@shadow

@cindex ellipsis
@end defun

@defun canvas.round_rectangle LINESTYLE, FILLSTYLE, X1,Y2,X2,Y2,RADIUS,SHADOW=None
@cindex marquee
@cindex round_rectangle
%dcanvas.round_rectangle
@shadow
@end defun

@defun canvas.curve LINESTYLE, [(X1,Y2), ..., (Xn, Yn)]
@cindex Bezier curve
Draw a Bezier curve. 
@end defun

@defun canvas.show X, Y, TEXT
@var{TEXT} supports font manipulation, as defined in @xref{font}.  
@cindex text

@end defun

@defun canvas.verbatim STR

This procedure outputs an arbitrary Postscript code @var{STR}.
@cindex Postscript
@end defun

@node Clipping, Redirecting output, canvas, Tricks
@section Clipping

@cindex clipping
@findex canvas.endclip

A rectangle, polygon, or ellipsis can be used to define a clipping
region.  Any drawing commands (@pxref{canvas}) issued afterwards are
confined in the region. You can even nest multiple clipping regions,
in which case, drawings will be clipped to the intersection of the
regions.  @code{canvas.endclip()} ends the clipping. Clipping commands
and @code{endclip()} must nest properly.

%icliptest
%-cliptest.py

@defun canvas.clip X1, Y1, X2, Y2,
%dcanvas.clip
@end defun

@defun canvas.clip_ellipsis X, Y, RADIUS, Y_ELONGATION
%dcanvas.ellipsis
@end defun

@defun canvas.clip_polygon [(X1,Y2),(X2,Y2), ..., (Xn, Yn)]
%dcanvas.clip_polygon
@end defun

@node Redirecting output,  , Clipping, Tricks
@section Redirecting output
@findex canvas.init
@cindex redirecting output
@cindex output file name
You can write to multiple files by calling @code{canvas.init()} before
calling Area's @code{draw()} method. 

@defun canvas.init FNAME
%dcanvas.init
@end defun

For example, the below example draws the first chart to @file{foo.pdf}
and the next chart to @file{bar.pdf}.

@example
canvas.init("foo.pdf")
ar = area.T(...)
ar.add_plot(...)
ar.draw()

canvas.init("bar.pdf")
ar = area.T(...)
ar.add_plot(...)
ar.draw()
@end example

@node Index,  , Tricks, Top
@unnumbered Index
@printindex cp
@bye

