Node:Options, Next:, Previous:Introduction, Up:Top



PyChart Options

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

Environment variable PYCHART_OPTIONS

The value of the environment variable PYCHART_OPTIONS, if any, should be a sequence of var=val, separated by space. The below example tells PyChart to write to file foo.pdf and use Times-Roman as the default font.

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

The summary of attributes that can be set via PYCHART_OPTIONS follows.

output=filename
Sets the output file name. Without this option, PyChart sends code to the standard output.
format=format

This option sets the encoding of the data produced by PyChart. Format must be one of the following:

ps
Encapsulated Postscript. This is the default.
pdf
Adobe Page Description Format, or PDF.
pdf-uncompressed
PDF without compression. This option should be used for a debugging purpose only.
png
PNG graphics. You need to have ghostscript (gs) installed to use this option, because PyChart internally calls ghostscript to convert ps to png.
svg
Scalable vector graphics.
x11
Interactive display on in X window. This format works on UNIX-based systems, but not on Windows. You need to have ghostscript installed to use this option.

Without this option, PyChart guesses the format from the file name (output=filename). Failing that, PyChart will generate encapsulated Postscript.

font-family=name
font-size=size

This option sets the default font family and size of texts. The default is Helvetica at 9 points. See font.

line-width=x
Set the default line width, in points (see Unit). The default value is 0.4. See line_style.
scale=n
Set the scaling factor (i.e., theme.scale_factor). The default value is 1.0. See Unit.
color=[yes|no]

If yes, PyChart colorizes default object attributes. In particular:

If the value is no, PyChart uses gray scale for the color of these objects. The default value of this option is no.

debug-level=N

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.

bbox=LEFT,BOTTOM,RIGHT,TOP
This option sets, expands, or shrinks the bounding box of the final output. PyChart usually calculates the right bounding box automatically. You use this option only when you want to override the calculation by PyChart, or PyChart screws the calculation. The latter situation happens especially when you use a really thick lines for drawing.

The value of this option is a sequence of four values, separated by commas. Each value is of the form, +num, -num, or num. +num and -num adds to or subtracts from the bounding-box value computed by PyChart (the unit is Postscript points; See Unit.) num sets the bounding box at that value. For example,

bbox=-10,0,+10,100

Extends the bounding box 10 points to both left and right, and sets the vertical stretch from 0 to 100.

Command-line options

The options can also be set from the command line. To do this, the program that imports Pychart must call theme.get_options in the beginning, because Pychart itself is just a library. Below is an example.

theme.get_options ARGV = sys.argv[1:] Function
This procedure takes a list of command line arguments in ARGV and parses options. It returns the non-parsed portion of ARGV. ARGV can be omitted, in which case its value defaults to sys.argv[1:]. The options supported are: "--format=[ps|png|pdf|x11]", "--output=FILE", "--color=[yes|no]" "--scale=X", "--font-family=NAME", "--font-size=X", "--line-width=X", "--debug-level=N", "bbox=LEFT,BOTTOM,RIGHT,TOP". The below code shows an example.

#!/usr/bin/python
from pychart import *
args = theme.get_options()
ar = area.T(...)
...

Setting variables manually

You can change PyChart's behavior by setting variables in the module theme directly. After setting values, you must call theme.reinitialize() to reflect the changes to other parts of PyChart.

theme.scale_factor = 3
theme.reinitialize()

The above example has the same effect as setting "PYCHART_OPTIONS="scale=3"".

theme.use_color Variable
Setting this variable to 1 has the same effect as setting color=yes in PYCHART_OPTIONS.

theme.output_format Variable
Equivalent to format= in PYCHART_OPTIONS. This option is meaningful only before calling area.draw() (see area).

theme.output_file Variable
Equivalent to output= in PYCHART_OPTIONS. This option is meaningful only before calling area.draw() (see area). If you want to produce multiple charts from a single Python source file, use canvas.init(FILE). See canvas.

theme.default_font_family Variable
Equivalent to font-family= in PYCHART_OPTIONS.

theme.default_font_size Variable
Equivalent to font-size= in PYCHART_OPTIONS.

theme.default_line_height Variable
Equivalent to line-height= in PYCHART_OPTIONS.


Footnotes

  1. In fact, you can use these color names in gray-scale mode as well. They will appear in some gray color though.