\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 PyChart Version 1.25.
PyChart 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

@image{linetest,}


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

@noindent
@strong{linetest.py}:
@example

# This line imports all the chart modules.
from pychart import *
theme.get_options()

# We have 10 sample points total.  The first value in each tuple is
# the X value, and subsequent values are Y values for different lines.
data = [(10, 20, 30), (20, 65, 33),
        (30, 55, 30), (40, 45, 51),
        (50, 25, 27), (60, 75, 30),
        (70, 80, 42), (80, 62, 32),
        (90, 42, 39), (100, 32, 39)]

# The format attribute speficies the text to be drawn at each tick mark.
# Here, texts are rotated -60 degrees ("/a-60"), left-aligned ("/hL"),
# and numbers are printed as integers ("%d"). 
xaxis = axis.X(format="/a-60/hL%d", tic_interval = 20, label="Stuff")
yaxis = axis.Y(tic_interval = 20, label="Value")

# Define the drawing area. "y_range=(0,None)" tells that the Y minimum
# is 0, but the Y maximum is to be computed automatically. Without
# y_ranges, Pychart will pick the minimum Y value among the samples,
# i.e., 20, as the base value of Y axis.
ar = area.T(x_axis=xaxis, y_axis=yaxis, y_range=(0,None))

# The first plot extracts Y values from the 2nd column
# ("ycol=1") of DATA ("data=data"). X values are takes from the first
# column, which is the default.
plot = line_plot.T(label="foo", data=data, ycol=1, tick_mark=tick_mark.star)
plot2 = line_plot.T(label="bar", data=data, ycol=2, tick_mark=tick_mark.square)

ar.add_plot(plot, plot2)

# The call to ar.draw() usually comes at the end of a program.  It
# draws the axes, the plots, and the legend (if any).

ar.draw()
@end example

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

PyChart 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 PyChart.  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

@image{bartestv,}


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

@example

from pychart import *
theme.get_options()

data = [(10, 20, 30, 5), (20, 65, 33, 5), (30, 55, 30, 5), (40, 45, 51, 7),
        (50, 25, 27, 3), (60, 75, 30, 5), (70, 80, 42, 5), (80, 62, 32, 5),
        (90, 42, 39, 5), (100, 32, 39, 4)]

# The attribute y_coord_system="category" tells that the Y axis values
# should be taken from samples, y_category_col'th column of
# y_category_data.  Thus, in this example, Y values will be
# [40,50,60,70,80].
ar = area.T(y_coord = category_coord.T(data[3:8], 0),
            x_grid_style=line_style.gray50_dash1,
            x_grid_interval=20,
            x_range = (0,100), 
            x_axis=axis.X(label="X label"),
            y_axis=axis.Y(label="Y label"),
            bg_style = fill_style.gray90,
            border_line_style = line_style.default)

# Below call sets the default attributes for all bar plots.
chart_object.set_defaults(bar_plot.T, direction="horizontal", data=data)

ar.add_plot(bar_plot.T(label="foo", cluster=(0,3)))
ar.add_plot(bar_plot.T(label="bar", hcol=2, cluster=(1,3)))
ar.add_plot(bar_plot.T(label="baz", hcol=3, cluster=(2,3)))
ar.draw()



@end example

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

The behavior of PyChart 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 PyChart 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, PyChart 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 PyChart. 
@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 PyChart 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, PyChart guesses the format from the file name
(@samp{output=}@var{filename}).  Failing to guess, PyChart 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, PyChart 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}, PyChart 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 PyChart. The
default value is 1, meaning that PyChart only displays error
messages. The larger the value, the more verbose PyChart 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:]
This procedure takes a list of command line arguments in ARGV and parses
    options. It returns the un-parsed portion of ARGV. ARGV can be
    omitted, in which case its value defaults to @code{sys.argv[1:]}.
    The options supported are: "@code{--format=[ps|png|pdf|x11]}",
    "@code{--output=}@var{FILE}", "@code{--color=[yes|no]}"
    "@code{--scale=}X", "@code{--font-family=}NAME", "@code{--font-size=}X",
    "@code{--line-width=}X",
    "@code{--debug-level=}N". The below code shows an example.

@example
@example
from pychart import *
args = theme.get_options()
ar = area.T(...)
...
@end example
    
@end example


@end defun

@section Setting variables manually
@pindex theme

You can change PyChart'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 PyChart.

@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}). PyChart 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 PyChart, 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 PyChart, 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 PyChart 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 PyChart 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
This function reads
    comma-separated samples from FILE. Empty lines and lines
    beginning with "#" are ignored.  DELIM specifies how
    values in each line are separated. If it does not contain the
    letter "%", then DELIM is simply used to split each
    line into values. Otherwise, this function acts like scanf
    in C:

@example
chart_data.read_csv("file", "%d,%s:%d")

@end example
    This function currently supports only three conversion specifiers:
    "d"(int), "f"(double), and "s"(string).


@end defun

@defun chart_data.fread_csv FP, DELIM=','
This function is similar to read_csv, except that it reads from
    an open file handle FP.

@example
fp = open("foo", "r")
data = chart_data.fread_csv(fp, ",") 

@end example


@end defun

@defun chart_data.read_str DELIM, LINES
This function is similar to read_csv, but it reads data from the
    list of LINES.

@example
fp = open("foo", "r")
data = chart_data.read_str(",", fp.readlines())

@end example


@end defun

@defun chart_data.func F, FROM, TO, STEP
Create sample points from function F, which must be a
    single-parameter function that returns a number (e.g., math.sin).
    XMIN and XMAX specify the first and last X values, and
    STEP specfies the sampling interval.

@example
sin_samples = chart_data.func(math.sin, 0, math.pi*4, 0.1)

@end example


@end defun

@defun chart_data.filter F, DATA
@findex Filter
FUNC must be a single-argument function that takes a sequence (i.e.,
a sample point) and returns a boolean. This procedure calls FUNC on
each element in DATA and returns a list comprising elements for
which FUNC returns true.

@example
>>> data = [[1,5], [2,10], [3,13], [4,16]]
... chart_data.filter(lambda x: x[1] % 2 == 0, data)
[[2,10], [4,16]].

@end example


@end defun

@defun chart_data.extract_rows DATA, ROWS...
Extract rows specified in the argument list.

@example
data2 = chart_data.extract_rows([[10,20], [30,40], [50,60]], 1, 2)
# data2 will become [[30,40],[50,60]].

@end example


@end defun

@defun chart_data.extract_columns DATA, COLS...
Extract columns specified in the argument list.

@example
data2 = chart_data.extract_columns([[10,20], [30,40], [50,60]], 0)
# data2 will become [[10],[30],[50]].

@end example


@end defun

@defun chart_data.transform FUNC, DATA
Apply FUNC on each element in DATA and return the list
consisting of the return values from FUNC.

@example
data = [[10,20], [30,40], [50,60]]
data2 = chart_data.transform(lambda x: [x[0], x[1]+1], data)
# data2 will become [[10, 21], [30, 41], [50, 61]].

@end example


@end defun

@defun chart_data.moving_average DATA, XCOL, YCOL, WIDTH
@cindex average
@cindex mean
Compute the moving average of  YCOL'th column of each sample point
in  DATA. In particular, for each element  I in  DATA,
this function extracts up to  WIDTH*2+1 elements, consisting of
 I itself,  WIDTH elements before  I, and  WIDTH
elements after  I. It then computes the mean of the  YCOL'th
column of these elements, and it composes a two-element sample
consisting of  XCOL'th element and the mean.

@example
data = [[10,20], [20,30], [30,50], [40,70], [50,5]]
data2 = chart_data.moving_average(data, 0, 1, 1)

@end example
@example
In the above example, data2 will be computed as:

@end example
@example
[(10, (20+30)/2), (20, (20+30+50)/3), (30, (30+50+70)/3), 
  (40, (50+70+5)/3), (50, (70+5)/2)]
@end example


@end defun

@defun chart_data.median DATA, COL=1
@cindex median
Compute the median of the COL'th column of the values is DATA.
    For example, chart_data.median([(10,20), (20,4), (30,5)], 0) returns 20.
    chart_data.median([(10,20), (20,4), (30,5)], 1) returns 5.
    


@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

XXX %%area.T

@deffn Attribute  bg_style  <class 'pychart.fill_style.T'>
Default: None. Background fill-pattern.
@end deffn

@deffn Attribute  border_line_style  <class 'pychart.line_style.T'>
Default: None. Line style of the outer frameof the chart.
@end deffn

@deffn Attribute  legend  <class 'pychart.legend.T'>
Default: a legend is by default displayed
               in the right-center of the chart.. The legend of the chart.
@end deffn

@deffn Attribute  loc  (x,y)
Default: (0, 0). The location of the bottom-left corner of the chart.
@cindex chart location
@cindex location, chart.
@end deffn

@deffn Attribute  size  (x,y)
Default: (120, 110). The size of the chart-drawing area, excluding axis labels,
              legends, tick marks, etc.
@cindex chart size
@cindex size, chart              
              
@end deffn

@deffn Attribute  x_axis  <class 'pychart.axis.X'>
Default: None. The X axis. @xref{axis}..
@end deffn

@deffn Attribute  x_coord  coord.T
Default: A linear coordinate system.. Set the X coordinate system. @xref{coord}..
@xref{coord}.
@end deffn

@deffn Attribute  x_grid_interval  Number or function
Default: None. The horizontal grid-line interval.
                        A numeric value
                        specifies the interval at which
                        lines are drawn. If value is a function, it
                        takes two arguments, (MIN, MAX), that tells
                        the minimum and maximum values found in the
                        sample data. The function should return a list
                        of values at which lines are drawn.
@end deffn

@deffn Attribute  x_grid_over_plot  int
Default: 0. If true, grid lines are drawn over plots. Otherwise, plots are drawn over grid lines.
@end deffn

@deffn Attribute  x_grid_style  <class 'pychart.line_style.T'>
Default: None. The style of horizontal grid lines.
@cindex grid lines
@end deffn

@deffn Attribute  x_range  (x,y)
Default: None. Specifies the range of X values that are displayed in the
    chart. IF the value is None, both the values are computed
    automatically from the samples.  Otherwise, the value must be a
    tuple of format (MIN, MAX). MIN and MAX must be either None or a
    number. If None, the value is computed automatically from the
    samples. For example, if x_range = (None,5), then the minimum X
    value is computed automatically, but the maximum X value is fixed
    at 5.
@end deffn

@deffn Attribute  y_axis  <class 'pychart.axis.Y'>
Default: None. The Y axis. @xref{axis}..
@end deffn

@deffn Attribute  y_coord  coord.T
Default: A linear coordinate system.. Set the Y coordinate system. @xref{coord}..
@xref{coord}.
@end deffn

@deffn Attribute  y_grid_interval  Number or function
Default: None. The vertical grid-line interval. See also x_grid_interval
@end deffn

@deffn Attribute  y_grid_over_plot  int
Default: 0. See x_grid_over_plot.
@end deffn

@deffn Attribute  y_grid_style  <class 'pychart.line_style.T'>
Default: line_style.gray70_dash3. The style of vertical grid lines.
@end deffn

@deffn Attribute  y_range  (x,y)
Default: None. Specifies the range of Y values that are displayed in the
    chart. IF the value is None, both the values are computed
    automatically from the samples.  Otherwise, the value must be a
    tuple of format (MIN, MAX). MIN and MAX must be either None or a
    number. If None, the value is computed automatically from the
    samples. For example, if y_range = (None,5), then the minimum Y
    value is computed automatically, but the maximum Y value is fixed
    at 5.
@end deffn


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 PyChart 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}. PyChart 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:

@example

from pychart import *
theme.get_options()
data = [["Jan", 10], ["Feb", 22], ["Mar", 30]]

ar = area.T(x_coord = category_coord.T(data, 0),
            y_range = (0, None),
            x_axis = axis.X(label="Month"),
            y_axis = axis.Y(label="Value"))
ar.add_plot(bar_plot.T(data = data, label = "Something"))
ar.draw()

            
            
            
@end example

The output will look like the below:

@image{categbar,}


@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.


@image{zaptest,}


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:

@example

from pychart import *

class zap_y_coord(linear_coord.T):
    # Method get_data_range is inherited from linear_coord.T.
    def get_canvas_pos(self, size, val, min, max):
        # Zap Y values between 70 and 240.
        # Thus, Y axis will display 0..70 and 240..280, 110 points total.
        if val <= 70:
            return linear_coord.T.get_canvas_pos(self, size, val, 0, 110)
        elif val <= 240:
            return linear_coord.T.get_canvas_pos(self, size, 70, 0, 110)
        else:
            return linear_coord.T.get_canvas_pos(self, size, val - 170, 0, 110)
    def get_tics(self, min, max, interval):
        # Don't draw tick marks between 65 and 245.
        tics = linear_coord.T.get_tics(self, min, max, interval)
        newtics = []
        
        # XXX should be using for..if construction ..
        for item in tics:
            if item < 65 or item > 245:
                newtics.append(item)
        return newtics

theme.get_options()
data = [(10, 20, 30, 5), (20, 265, 33, 5),
        (30, 255, 30, 5), (40, 45, 51, 7), (50, 25, 27, 3)]

chart_object.set_defaults(area.T, size = (150, 120), y_range = (0, 280),
                          y_coord = zap_y_coord(),
                          x_coord = category_coord.T(data, 0))

chart_object.set_defaults(bar_plot.T, data = data)

ar = area.T(loc=(250,0),
            x_axis=axis.X(label="X label", format="/a-30@{@}%d"),
            y_axis=axis.Y(label="Y label", tic_interval=10))

bar_plot.fill_styles.reset();
plot1=bar_plot.T(label="foo", cluster=(0,3))
plot2=bar_plot.T(label="bar", hcol=2, cluster=(1,3))
plot3=bar_plot.T(label="baz", hcol=3, cluster=(2,3))

ar.add_plot(plot1, plot2, plot3)
ar.draw()
for x in (ar.x_pos(10) - 20,
          ar.x_pos(20)- 10,
          ar.x_pos(30) - 10):
    zap.zap_horizontally(line_style.default, fill_style.white,
                         x, ar.y_pos(65),
                         x+16, ar.y_pos(65) + 4,
                         4, 4)

                     

@end example

@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

XXX %%axis.X

@deffn Attribute  format  printf format string
Default: "%s". The format string for tick labels.
                  It can be a `printf' style format string, or 
                  a single-parameter function that takes an X (or Y) value
                  and returns a string. The appearance of the string produced here can be
controlled using escape sequences. @xref{font}.
@end deffn

@deffn Attribute  label  str
Default: "axis label". The descriptive string displayed below (or in the left of) the axis. @xref{font}..
@end deffn

@deffn Attribute  label_offset  (x,y) or None
Default: (None, None). The location for drawing the axis label, 
                        relative to the middle point of the axis.
                        If the value is None, the label is displayed
                        below (or in the left of) of axis at the middle.
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. Specifies the style of axis and tick lines. @xref{line_style}..
@end deffn

@deffn Attribute  minor_tic_interval  Number or function
Default: None. When the value is a number, it specifies the interval at which minor tick marks are drawn. Otherwise, the value must be a function that takes no argument and returns the list of numbers. The return value specifies the X or Y points at which minor tick marks are drawn.
@end deffn

@deffn Attribute  minor_tic_len  number
Default: 3. The length of minor tick marks.  The value can be negative, in which case the tick lines are drawn right of (or above) the axis.
@end deffn

@deffn Attribute  offset  number
Default: 0. The location of the axis. The unit is points.
                  The value of 0 draws the
                  axis at the left (for the Y axis) or bottom (for the X axis)
                  edge of the drawing area.
                  
@end deffn

@deffn Attribute  tic_interval  Number or function
Default: None. When the value is a number, it specifies the interval at which tick marks are drawn. Otherwise, the value must be a function that takes no argument and returns the list of numbers. The return value specifies the X or Y points at which tick marks are drawn.
@end deffn

@deffn Attribute  tic_label_offset  (x,y)
Default: (0, 0). The location for drawing tick labels, 
                            relative to the tip of the tick line.
@end deffn

@deffn Attribute  tic_len  number
Default: 6. The length of tick lines. The value can be negative, in which case the tick lines are drawn right of (or above) the axis.
@end deffn


@item axis.Y

XXX %%axis.Y

@deffn Attribute  format  printf format string
Default: "%s". The format string for tick labels.
                  It can be a `printf' style format string, or 
                  a single-parameter function that takes an X (or Y) value
                  and returns a string. The appearance of the string produced here can be
controlled using escape sequences. @xref{font}.
@end deffn

@deffn Attribute  label  str
Default: "axis label". The descriptive string displayed below (or in the left of) the axis. @xref{font}..
@end deffn

@deffn Attribute  label_offset  (x,y) or None
Default: (None, None). The location for drawing the axis label, 
                        relative to the middle point of the axis.
                        If the value is None, the label is displayed
                        below (or in the left of) of axis at the middle.
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. Specifies the style of axis and tick lines. @xref{line_style}..
@end deffn

@deffn Attribute  minor_tic_interval  Number or function
Default: None. When the value is a number, it specifies the interval at which minor tick marks are drawn. Otherwise, the value must be a function that takes no argument and returns the list of numbers. The return value specifies the X or Y points at which minor tick marks are drawn.
@end deffn

@deffn Attribute  minor_tic_len  number
Default: 3. The length of minor tick marks.  The value can be negative, in which case the tick lines are drawn right of (or above) the axis.
@end deffn

@deffn Attribute  offset  number
Default: 0. The location of the axis. The unit is points.
                  The value of 0 draws the
                  axis at the left (for the Y axis) or bottom (for the X axis)
                  edge of the drawing area.
                  
@end deffn

@deffn Attribute  tic_interval  Number or function
Default: None. When the value is a number, it specifies the interval at which tick marks are drawn. Otherwise, the value must be a function that takes no argument and returns the list of numbers. The return value specifies the X or Y points at which tick marks are drawn.
@end deffn

@deffn Attribute  tic_label_offset  (x,y)
Default: (0, 0). The location for drawing tick labels, 
                            relative to the tip of the tick line.
@end deffn

@deffn Attribute  tic_len  number
Default: 6. The length of tick lines. The value can be negative, in which case the tick lines are drawn right of (or above) the axis.
@end deffn

@end vtable

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

XXX %%bar_plot.T

@deffn Attribute  bcol  int
Default: 0. Specifies the column from which base values (i.e., X values when attribute "direction" is "vertical", Y values otherwise) are extracted.
The
              combination of "data", "bcol", and "hcol" attributes defines
              the set of boxes drawn by this chart. See the
              below example:
              
@example
              d = [[5,10], [7,22], [8,25]]
              p = bar_plot.T(data = d, bcol = 1, hcol = 2)
@end example

              Here, three bars will be drawn. The X values of the bars
              will be 5, 7, and 8. The Y values of the bars will be
              10, 22, and 25, respectively. (In practice, because
              the values of bcol and hcol defaults to 1 and 2, you can
              write the above example just as "p = bar_plot.T(data = d)".
              
@end deffn

@deffn Attribute  cluster  tuple
Default: (0, 1). This attribute is used to
    cluster multiple bar plots side by side in a single chart.
    The value should be a tuple of two integers. The second value should be equal to the total number of bar plots in the chart. The first value should be the relative position of this chart; 0 places this chart the leftmost, and N-1
    (where N is the 2nd value of this attribute) places this chart the rightmost. Consider the below example:

@example
    a = area.T(...)
    p1 = bar_plot.T(data = [[1,20][2,30]], cluster=(0,2))
    p2 = bar_plot.T(data = [[1,25],[2,10]], cluster=(1,2))
    a.add_plot(p1, p2)
    a.draw()
@end example

    In this example, one group of bars will be drawn side-by-side at
    position x=1, one with height 20, the other with height 25. The
    other two bars will be drawn side by side at position x=2, one
    with height 30 and the other with height 10.
    
@end deffn

@deffn Attribute  cluster_sep  number
Default: 0. The separation between
    clustered boxes. The unit is points.
@end deffn

@deffn Attribute  data  any
Default: None. Specifies the data points. @xref{chart_data}.
@end deffn

@deffn Attribute  data_label_format  printf format string
Default: None. The
                          format string for the label displayed besides each
                          bar.  It can be a `printf' style format
                          string, or a two-parameter function that
                          takes (x,y) values and returns a string. The appearance of the string produced here can be
controlled using escape sequences. @xref{font}.
@end deffn

@deffn Attribute  data_label_offset  (x,y)
Default: (0, 5). The location of data labels relative to the sample point. See also attribute data_label_format.
@end deffn

@deffn Attribute  direction  str
Default: "vertical". The direction the growth of the bars. The value is either 'horizontal'
                   or 'vertical'.
@end deffn

@deffn Attribute  error_bar  <class 'pychart.error_bar.Base'>
Default: None. The style of the error bar. @xref{error_bar}.
@end deffn

@deffn Attribute  error_minus_col  int
Default: None. Specifies the column from which the depth of the errorbar is extracted.  This attribute is meaningful only when
                  error_bar != None.
@cindex error bars, bar chart
                  
@end deffn

@deffn Attribute  error_plus_col  int
Default: None. The depth of the errorbar is extracted from 
                  this column in data. This attribute is meaningful only
                  when error_bar != None.
@end deffn

@deffn Attribute  fill_style  <class 'pychart.fill_style.T'>
Default: By default, a style is picked from standard styles round-robin. @xref{fill_style}.. Fill style of each box.
@end deffn

@deffn Attribute  hcol  int
Default: 1. The column from which the height of each bar is extracted.
             See also the description of the 'bcol' attribute.
@end deffn

@deffn Attribute  label  str
Default: "???". The label to be displayed in the legend. @xref{legend}., @xref{font}.
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. The style of the outer frame of each box.
@end deffn

@deffn Attribute  qerror_minus_col  int
Default: None. The depth of the "quartile" errorbar is extracted from 
                  this column in data. This attribute is meaningful only
                  when error_bar != None. 
@end deffn

@deffn Attribute  qerror_plus_col  int
Default: None. The depth of the "quartile" errorbar is extracted from 
                  this column in data. This attribute is meaningful only
                  when error_bar != None.
@end deffn

@deffn Attribute  stack_on  any
Default: None. The value must be either None or bar_plot.T. If not None, bars of this plot are stacked on top of another bar plot.
@end deffn

@deffn Attribute  width  number
Default: 5. Width of each box. The unit is in points.
@cindex width, bar chart
@cindex size, bar chart

@end deffn


@image{bartest,,}

 Sample bar charts 

Below is the source code that produces the above chart.
@example

from pychart import *
theme.get_options()

data = [(10, 20, 30, 5), (20, 65, 33, 5),
        (30, 55, 30, 5), (40, 45, 51, 7), (50, 25, 27, 3)]

chart_object.set_defaults(area.T, size = (150, 120), y_range = (0, None),
                          x_coord = category_coord.T(data, 0))

chart_object.set_defaults(bar_plot.T, data = data)

# Draw the 1st graph. The Y upper bound is calculated automatically.
ar = area.T(x_axis=axis.X(label="X label", format="/a-30@{@}%d"),
            y_axis=axis.Y(label="Y label", tic_interval=10))

plot1=bar_plot.T(label="foo", cluster=(0, 3))
plot2=bar_plot.T(label="bar", hcol=2, cluster=(1, 3))
plot3=bar_plot.T(label="baz", hcol=3, cluster=(2, 3))
ar.add_plot(plot1, plot2, plot3)
ar.draw()

ar = area.T(legend = legend.T(), loc=(250,0),
            x_axis=axis.X(label="X label", format="/a-30@{@}%d"),
            y_axis=axis.Y(label="Y label", tic_interval=10))

bar_plot.fill_styles.reset();
plot1=bar_plot.T(label="foo")
plot2=bar_plot.T(label="bar", hcol=2, stack_on = plot1)
plot3=bar_plot.T(label="baz", hcol=3, stack_on = plot2)

ar.add_plot(plot1, plot2, plot3)
ar.draw()


@end example
@image{bartestv,,}

 Vertical bar chart 

Below is the source code that produces the above chart.
@example

from pychart import *
theme.get_options()

data = [(10, 20, 30, 5), (20, 65, 33, 5), (30, 55, 30, 5), (40, 45, 51, 7),
        (50, 25, 27, 3), (60, 75, 30, 5), (70, 80, 42, 5), (80, 62, 32, 5),
        (90, 42, 39, 5), (100, 32, 39, 4)]

# The attribute y_coord_system="category" tells that the Y axis values
# should be taken from samples, y_category_col'th column of
# y_category_data.  Thus, in this example, Y values will be
# [40,50,60,70,80].
ar = area.T(y_coord = category_coord.T(data[3:8], 0),
            x_grid_style=line_style.gray50_dash1,
            x_grid_interval=20,
            x_range = (0,100), 
            x_axis=axis.X(label="X label"),
            y_axis=axis.Y(label="Y label"),
            bg_style = fill_style.gray90,
            border_line_style = line_style.default)

# Below call sets the default attributes for all bar plots.
chart_object.set_defaults(bar_plot.T, direction="horizontal", data=data)

ar.add_plot(bar_plot.T(label="foo", cluster=(0,3)))
ar.add_plot(bar_plot.T(label="bar", hcol=2, cluster=(1,3)))
ar.add_plot(bar_plot.T(label="baz", hcol=3, cluster=(2,3)))
ar.draw()



@end example

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

XXX %%line_plot.T

@deffn Attribute  data  any
Default: None. Specifies the data points. @xref{chart_data}.
@end deffn

@deffn Attribute  data_label_format  printf format string
Default: None. The format string for the label printed 
                          beside a sample point.
                          It can be a `printf' style format string, or 
                          a two-parameter function that takes the (x, y)
                          values and returns a string. The appearance of the string produced here can be
controlled using escape sequences. @xref{font}.
@end deffn

@deffn Attribute  data_label_offset  (x,y)
Default: (0, 5). The location of data labels relative to the sample point. Meaningful only when data_label_format != None.
@end deffn

@deffn Attribute  error_bar  <class 'pychart.error_bar.Base'>
Default: None. The style of the error bar. @xref{error_bar}.
@end deffn

@deffn Attribute  label  str
Default: "???". The label to be displayed in the legend. @xref{legend}., @xref{font}.
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: By default, a style is picked from standard styles round-robin. @xref{line_style}.. The style of the line. 
@end deffn

@deffn Attribute  tick_mark  <class 'pychart.tick_mark.Base'>
Default: None. Tick marks to be displayed at each sample point.
@end deffn

@deffn Attribute  xcol  int
Default: 0. The column, within "data", from which the X values of sample points are extracted. @xref{chart_data}.
@end deffn

@deffn Attribute  y_error_minus_col  int
Default: 2. The column (within "data") from which the depth of the errorbar is extracted. Meaningful only when error_bar != None. @xref{error_bar}.
@end deffn

@deffn Attribute  y_error_plus_col  int
Default: None. The column (within "data") from which the height of the errorbar is extracted. Meaningful only when error_bar != None. @xref{error_bar}.
@end deffn

@deffn Attribute  y_qerror_minus_col  int
Default: None. @xref{error_bar}.
@end deffn

@deffn Attribute  y_qerror_plus_col  int
Default: None. @xref{error_bar}.
@end deffn

@deffn Attribute  ycol  int
Default: 1. The column, within "data", from which the Y values of sample points are extracted. @xref{chart_data}.
@end deffn


@image{linetest3,,}

 Sample line plot 

Below is the source code that produces the above chart.
@example

from pychart import *

theme.get_options()

data = chart_data.read_csv("lines.csv")

xaxis=axis.X(label="X", tic_interval=10)
yaxis=axis.Y(label="Y", tic_interval=10)
ar = area.T(x_range=(0,100), y_range=(0,100), x_axis=xaxis, y_axis=yaxis)
eb = error_bar.error_bar2(tic_len=5, hline_style=line_style.gray50)
ar.add_plot(line_plot.T(label="foo", data=data, error_bar=eb, y_error_minus_col=3),
            line_plot.T(label="bar", data=data, ycol=2, error_bar=eb, y_error_minus_col=3))
ar.draw()

tb = text_box.T(loc=(40, 130), text="This is\nimportant!", line_style=None)
tb.add_arrow((ar.x_pos(data[6][0]), ar.y_pos(data[6][1])), "cb")
tb.draw()

ar = area.T(loc=(200, 0), x_range=(0,100), y_range=(0,100),
            x_axis=xaxis, y_axis=yaxis, legend=legend.T())
ar.add_plot(line_plot.T(label="foo", data=data, data_label_format="/8@{@}%d"),
            line_plot.T(label="bar", data=data, ycol=2))
ar.draw()

@end example

@cindex Scatter plot

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

@image{scattertest,,}

 Sample scatter plot 

Below is the source code that produces the above chart.
@example

from pychart import *
import whrandom

def randomdata():
    data = []
    for i in range(0, 30):
        data.append((whrandom.random() * 1000, whrandom.random() * 1000))
    return data

theme.get_options()
chart_object.set_defaults(line_plot.T, line_style=None)

tick1 = tick_mark.Circle(size=2)
tick2 = tick_mark.Circle(size=2, fill_style=fill_style.black)
xaxis = axis.X(label="foo", format="/a-60@{@}%d")
yaxis = axis.Y(label="bar")

ar = area.T(x_axis=xaxis, y_axis=yaxis,
            x_grid_interval=100, x_grid_style=line_style.gray70_dash3,
            legend = legend.T(loc=(350, 50)), loc = (0, 0))

ar.add_plot(line_plot.T(label="plot1", data=randomdata(), tick_mark=tick1))
ar.add_plot(line_plot.T(label="plot2", data=randomdata(), tick_mark=tick2))
ar.draw()

xaxis = axis.X(label="foo", format="/a-30@{@}%d")
yaxis = axis.Y(label="bar")
ar = area.T(x_axis=xaxis, y_axis=yaxis, 
            x_coord=log_coord.T(), y_coord=log_coord.T(), loc = (200, 0),
            legend = None)

ar.add_plot(line_plot.T(label="plot1", data=randomdata(), tick_mark=tick1))
ar.add_plot(line_plot.T(label="plot2", data=randomdata(), tick_mark=tick2))
ar.draw()

@end example

@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}:

XXX %%tick_mark.Base

@deffn Attribute  fill_style  <class 'pychart.fill_style.T'>
Default: fill_style.white. The fill style.
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. The line style of the tick mark.
@end deffn

@deffn Attribute  size  number
Default: 5. Size of the tick mark.
@end deffn


Several types of tick marks are offered by PyChart 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.

@image{tickmarks,}


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

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

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. @xref{line_style}.
@end deffn

@deffn Attribute  tic_len  number
Default: 10. Length of the horizontal bars
@end deffn


@item error_bar.error_bar2
XXX %%error_bar.error_bar2

@deffn Attribute  hline_style  <class 'pychart.line_style.T'>
Default: line_style.black. The style of the horizontal bars. @xref{line_style}..
@end deffn

@deffn Attribute  tic_len  number
Default: 3. The length of the horizontal bars
@end deffn

@deffn Attribute  vline_style  <class 'pychart.line_style.T'>
Default: None. The style of the vertical bar.
@end deffn


@item error_bar.error_bar3
XXX %%error_bar.error_bar3

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. 
@end deffn


@item error_bar.error_bar4
XXX %%error_bar.error_bar4

@deffn Attribute  box_width  number
Default: 4. 
@end deffn

@deffn Attribute  fill_style  <class 'pychart.fill_style.T'>
Default: fill_style.gray70. 
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. 
@end deffn

@deffn Attribute  tic_len  number
Default: 4. 
@end deffn


@end table

@image{errorbars,}


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

XXX %%range_plot.T

@deffn Attribute  data  any
Default: None. Specifies the data points. @xref{chart_data}.
@end deffn

@deffn Attribute  fill_style  <class 'pychart.fill_style.T'>
Default: fill_style.default. 
@end deffn

@deffn Attribute  label  str
Default: "???". The label to be displayed in the legend. @xref{legend}., @xref{font}.
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. The style of the boundary line.
@end deffn

@deffn Attribute  max_col  int
Default: 2. The upper bound of the sweep is extracted from this column of data.
@end deffn

@deffn Attribute  min_col  int
Default: 1. The lower bound of the sweep is extracted from this column of data.
@end deffn

@deffn Attribute  xcol  int
Default: 0. The column, within "data", from which the X values of sample points are extracted. @xref{chart_data}.
@end deffn


@image{rangetest,,}

 Sample range plot 

Below is the source code that produces the above chart.
@example

from pychart import *

data = [ (0, 10, 30, 40, 60),
         (10, 20, 40, 50, 55),
         (20, 10, 35, 38, 43),
         (30, 8, 30, 35, 39),
         (40, 8, 20, 28, 39) ]

ar = area.T(x_axis = axis.X(label="X axis"),
            y_grid_interval = 10, y_grid_style = line_style.white,
            y_axis = axis.Y(label="Y axis"),
            y_grid_over_plot=1, legend = legend.T())

if theme.use_color:
    colors = [ fill_style.darkseagreen, fill_style.white, fill_style.brown]
else:
    colors = [ fill_style.gray90, fill_style.white, fill_style.gray50]
ar.add_plot(range_plot.T(label="foo", data=data, fill_style = colors[0]))
ar.add_plot(range_plot.T(label="bar", data=data, min_col=2, max_col=3,
                         fill_style = colors[1]))
ar.add_plot(range_plot.T(label="baz", data=data, min_col=3, max_col=4, fill_style = colors[2]))
ar.draw()

@end example

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

XXX %%pie_plot.T

@deffn Attribute  arc_offsets  list
Default: None. You can draw each pie "slice" offset from the
                         center of the circle. This attribute specifies the
                         amount of offset (in points) from the center.
                         The value of None will draw the slice archored at the
                         center.
@end deffn

@deffn Attribute  arrow_style  <class 'pychart.arrow.T'>
Default: None. The style of arrow that connects a label
                        to the corresponding "pie".
@end deffn

@deffn Attribute  center  (x,y)
Default: None. 
@end deffn

@deffn Attribute  data  any
Default: None. Specifies the data points. @xref{chart_data}.
@end deffn

@deffn Attribute  data_col  int
Default: 1.  The column, within "data", from which the data values are retrieved.
@end deffn

@deffn Attribute  fill_styles  list
Default: ['fill_style.black', 'fill_style.gray70', 'fill_style.diag', 'fill_style.gray30', 'fill_style.rdiag', 'fill_style.gray10', 'fill_style.diag2', 'fill_style.white', 'fill_style.rdiag2', 'fill_style.vert', 'fill_style.diag3', 'fill_style.gray50', 'fill_style.horiz', 'fill_style.gray90', 'fill_style.rdiag3', 'fill_style.wave', 'fill_style.vwave', 'fill_style.stitch', 'fill_style.lines']. The fill style of each item. The length of the
                         list should be equal to the length of the data. 
                         
@end deffn

@deffn Attribute  label_col  int
Default: 0. The column, within "data", from which the labels of items are retrieved.
@end deffn

@deffn Attribute  label_fill_style  <class 'pychart.fill_style.T'>
Default: fill_style.default. 
@end deffn

@deffn Attribute  label_line_style  <class 'pychart.line_style.T'>
Default: None. 
@end deffn

@deffn Attribute  label_offset  number
Default: None. 
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. 
@end deffn

@deffn Attribute  radius  number
Default: None. 
@end deffn

@deffn Attribute  shadow  (xoff,yoff,fill)
Default: None. The value is either None or a tuple. When non-None,
a drop-shadow is drawn beneath the object. X-off, and y-off specifies the
offset of the shadow relative to the object, and fill specifies the
style of the shadow (@pxref{fill_style}).
@end deffn

@deffn Attribute  start_angle  number
Default: 90. The angle at which the first item is drawn.
@end deffn


@image{pietest,,}

 Sample pie chart 

Below is the source code that produces the above chart.
@example

from pychart import *

import sys
data = [("foo", 10),("bar", 20), ("baz", 30), ("ao", 40)]

ar = area.T(size=(150,150), legend=legend.T(),
            x_grid_style = None, y_grid_style = None)

plot = pie_plot.T(data=data, arc_offsets=[0,10,0,10],
                  shadow = (2, -2, fill_style.gray50),
                  label_offset = 25,
                  arrow_style = arrow.a3)
ar.add_plot(plot)
ar.draw()


@end example

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

XXX %%legend.T

@deffn Attribute  bottom_fudge  number
Default: 3. Amount of space below the last line.
@end deffn

@deffn Attribute  frame_fill_style  <class 'pychart.fill_style.T'>
Default: fill_style.white. 
@end deffn

@deffn Attribute  frame_line_style  <class 'pychart.line_style.T'>
Default: line_style.black. 
@end deffn

@deffn Attribute  inter_col_sep  number
Default: 0. Space between each column in the legend.
@end deffn

@deffn Attribute  inter_row_sep  number
Default: 0. Space between each row in the legend.
@end deffn

@deffn Attribute  left_fudge  number
Default: 5. Amount of space left of the legend.
@end deffn

@deffn Attribute  loc  (x,y)
Default: None. Bottom-left corner of the legend.
@end deffn

@deffn Attribute  nr_rows  int
Default: 9999. Number of rows in the legend. If the number of plots in a chart is larger than nr_rows, multiple columns are created for their legends.
@end deffn

@deffn Attribute  right_fudge  number
Default: 5. Amount of space right of the legend.
@end deffn

@deffn Attribute  shadow  (xoff,yoff,fill)
Default: None. The value is either None or a tuple. When non-None,
a drop-shadow is drawn beneath the object. X-off, and y-off specifies the
offset of the shadow relative to the object, and fill specifies the
style of the shadow (@pxref{fill_style}).
@end deffn

@deffn Attribute  top_fudge  number
Default: 0. Amount of space above the first line.
@end deffn


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

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

XXX %%line_style.T

@deffn Attribute  cap_style  int
Default: 0. Defines the style of the tip of the line segment.
                  0: butt cap (square cutoff, with no projection beyond),
                  1: round cap (arc), 2: projecting square cap
                  (square cutoff, but the line extends half the line width).
                  See also Postscript/PDF reference manual.
@end deffn

@deffn Attribute  color  <class 'pychart.color.T'>
Default: color.black. The color of the line.
@end deffn

@deffn Attribute  dash  tuple
Default: None. The value
              of None will draw a solid line. Otherwise, this
              attribute specifies the style of dashed lines. 
              The 2N'th value specifies the length of the line (in points), 
              and 2N+1'th value specfies the length of the blank.

              For example, the dash style of (3,2,4,1) draws a dashed line that
              looks like @samp{---__----_---__----_...}.
              
@end deffn

@deffn Attribute  join_style  int
Default: 0. Join style. 0: Miter join (sharp, pointed corners),
                   1: round join (rounded corners),
                   2: bevel join (flattened corners).
                   See also Postscript/PDF reference manual.
@end deffn

@deffn Attribute  width  number
Default: 0.4. Width of the line, in points.
@end deffn


@image{linestyles,}


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

XXX %%color.T

@deffn Attribute  b  number
Default: 0.0. The intensity of blue. The value is between 0 and 1.
@end deffn

@deffn Attribute  g  number
Default: 0.0. The intensity of green. The value is between 0 and 1.
@end deffn

@deffn Attribute  r  number
Default: 0.0. The intensity of red. The value is between 0 and 1.
@end deffn


@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}).

@image{colors,}


@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. 

XXX %%fill_style.T

@deffn Attribute  bgcolor  <class 'pychart.color.T'>
Default: color.white. The background color.
@end deffn

@deffn Attribute  line_interval  number
Default: 3. The interval between successive stitch lines.
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. The style of the line. 
@end deffn


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

@deffn Class fill_style.Plain
This class just fills the region with the solid background color.
Attributes line_style and line_interval are ignored.


@end deffn

@deffn Class fill_style.Diag
This class fills the region with diagonal lines.


@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.

@image{fillstyles,}


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
Quote letters with special meanings in pychart so that TEXT will display
    as-is when passed to canvas.show(). For example,
    font.quotemeta("foo/bar") will return "foo//bar". 


@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

@image{fonttest,}


@example

from pychart import *
import re

x = 100
y = 500

def show_text(str):
    global x, y
    canvas.show(x, y, str)
    e = "/16/C" + font.quotemeta(str)
    canvas.show(x+200, y, e)
    y = y - 20

show_text("/16/hLLeft align")
show_text("/16/hRRight align")
show_text("/16/hCCenter align")
show_text("/a20/16/hRAngled text")

def show_textv(str):
    global x, y
    canvas.show(x, y, str)
    x = x + 150

y = y - 40
x = 100
show_textv("/16/vT//16//vTTop align")
show_textv("/16/vM//16//vT/16Middle align")
show_textv("/16/vB//16//vT/16Bottom align")

y = y - 40
x = 100
show_text("/16/HHelvetica")
show_text("/16/CCourier")
show_text("/16/NHelvetica-Narrow")
show_text("/16/PPalatino-Roman")
show_text("/16/AAvantgarde")
show_text("/16/T/iTimes-Italic")
show_text("/16/F@{ZapfDingbats@}ZapfDingbats")

@end example

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

XXX %%text_box.T

@deffn Attribute  arrows  list
Default: pychart_util.new_list. The list of arrows. Not to be touched by the user directly
@end deffn

@deffn Attribute  bottom_fudge  number
Default: 5. The amount of space below the last line
@end deffn

@deffn Attribute  fill_style  <class 'pychart.fill_style.T'>
Default: fill_style.white. The fill style. @xref{fill_style}..
@end deffn

@deffn Attribute  left_fudge  number
Default: 5. The amount of space left of the box
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. The line style of the surrounding frame.
                           @xref{line_style}..
@end deffn

@deffn Attribute  loc  tuple
Default: (0, 0). The location of the text box.
@end deffn

@deffn Attribute  radius  number
Default: 0. Radius of the four corners of the rectangle.
                       If the value is zero, a sharp-cornered
                       rectangle is drawn.
@end deffn

@deffn Attribute  right_fudge  number
Default: 5. The amount of space right of the box
@end deffn

@deffn Attribute  shadow  (xoff,yoff,fill)
Default: None. The value is either None or a tuple. When non-None,
a drop-shadow is drawn beneath the object. X-off, and y-off specifies the
offset of the shadow relative to the object, and fill specifies the
style of the shadow (@pxref{fill_style}).
@end deffn

@deffn Attribute  text  str
Default: "???". Text body. @xref{font}.
@end deffn

@deffn Attribute  top_fudge  number
Default: 0. The amount of space (in points) above the first line
@end deffn


@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

@image{annotations,}


@example

from pychart import *

a1 = text_box.T(loc=(100,100), text="Without frame")
a1.add_arrow((50, 100))
a1.add_arrow((180, 100))
a1.draw()

a1 = text_box.T(loc=(100,130), text="/hCMulti\n/bLine")
a1.add_arrow((50, 120))
a1.add_arrow((180, 100))
a1.draw()

a1 = text_box.T(loc=(100,160), text="Fat arrow", line_style=None)
a1.add_arrow((180, 140), tail='rm', arrow = arrow.fat1)
a1.draw()

a1 = text_box.T(loc=(180, 100), text="/a90Funny background",
                fill_style = fill_style.gray70)
a1.draw()

a1 = text_box.T(loc=(180, 140), text="/hL/20Big/oText\n/24/bHuge/oText",
                fill_style = None)
a1.draw()

@end example

@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

XXX %%arrow.T

@deffn Attribute  head_color  <class 'pychart.color.T'>
Default: color.black. The color of the arrow head.
@end deffn

@deffn Attribute  head_len  number
Default: 8. The length of the arrow head.
@end deffn

@deffn Attribute  head_style  int
Default: 1. The value of 0 draws a triangular arrow head. 1 draws a swallow-tail arrow head
@end deffn

@deffn Attribute  line_style  <class 'pychart.line_style.T'>
Default: line_style.black. Line style.
@end deffn

@deffn Attribute  thickness  number
Default: 4. The width of the arrow head.
@end deffn


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

@deffn Method draw SELF POINTS
Points: The list of points the arrow traverses.
        It should contain at least two points, ie
        the tail and tip.


@end deffn

@image{arrows,}



@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 PyChart, 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

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}). 

@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.
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}). 

@cindex ellipsis
@end defun

@defun canvas.round_rectangle LINESTYLE, FILLSTYLE, X1,Y2,X2,Y2,RADIUS,SHADOW=None
@cindex marquee
@cindex round_rectangle
Draw a rectangle with rounded four corners.


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 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.

@image{cliptest,}

@example

from pychart import *

data = [(10, 20), (20, 65), (30, 55), (40, 45)]

# tic_angle is the angle X values are displayed below the axis.
xaxis = axis.X(label="Stuff")
yaxis = axis.Y(label="Value")

ar = area.T(x_axis=xaxis, y_axis=yaxis)

plot = line_plot.T(label="foo", data=data, xcol=0, ycol=1,
                   tick_mark=tick_mark.star)

ar.add_plot(plot)
canvas.ellipsis(line_style.T(width=1.5,dash=(4,4)), None, 30, 20, 80, 0.8)
canvas.clip_ellipsis(30, 20, 80, 0.8)
ar.draw()
canvas.endclip()


@end example

@defun canvas.clip X1, Y1, X2, Y2,
Activate a rectangular clip region, (X1, Y1) - (X2, Y2).
    You must call endclip() after you completed drawing.

@example
canvas.clip(x,y,x2,y2)
draw something ...
canvas.endclip()
    
@end example


@end defun

@defun canvas.clip_ellipsis X, Y, RADIUS, Y_ELONGATION
Draw an ellipsis with line_style and fill PATTERN. The center is     (X, Y), X radius is RADIUS, and Y radius is RADIUS*RATIO, whose     default value is 1.0. SHADOW is either None or a tuple (XDELTA,
    YDELTA, fillstyle). If non-null, a shadow of FILLSTYLE is drawn
    beneath the polygon at the offset of (XDELTA, YDELTA).


@end defun

@defun canvas.clip_polygon [(X1,Y2),(X2,Y2), ..., (Xn, Yn)]
Create a polygon clip region. You must call endclip() after
    you completed drawing. See also the polygon method.


@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
Open a new canvas. Close the existing canvas, if any.
    Parameter ``fname`` specifies the file to which the contents of
    the canvas will be dumped when it closes.  The format of the file
    is determined by variable ``theme.output_format``, or if it's
    None, by ``fname``'s suffix -- i.e., PDF if the file name ends
    with ``.pdf``, PNG if the file name ends with ``.png``, and
    Encapsulated PS otherwise.  


@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

