updates to the manual, some comments on TODOs for 0.6
[PyX.git] / manual / graph.tex
blobe684e72c1b627cb95aca9449c34e8ade83e7e9bf
1 \chapter{Graphs\label{graph}}
2 \section{Introduction}
3 \PyX{} can be used for data and function plotting. At present only
4 x-y-graphs are supported. However, the component architecture of the
5 graph system described in section \ref{graph:components} allows for
6 additional graph geometries while reusing most of the existing
7 components.
9 Creating a graph splits into two basic steps. First you have to create
10 a graph instance. The most simples form would look like:
11 \begin{verbatim}
12 from pyx import *
13 g = graph.graphxy(width=8)
14 \end{verbatim}
15 The graph instance \code{g} created in this example can than be used
16 to actually plot something into the graph. Suppose you have some data
17 in a file \file{graph.dat} you want to plot. The content of the file
18 could look like:
19 \verbatiminput{graph.dat}
20 To plot these data into the graph \code{g} you must perform:
21 \begin{verbatim}
22 g.plot(graph.data.file("graph.dat", x=1, y=2))
23 \end{verbatim}
24 The method \method{plot()} takes the data to be plotted and optionally
25 a graph style to be used to plot the data. When no style is provided,
26 a default style defined by the data instance is used. For data read
27 from a file by an instance of \class{graph.data.file}, the default are
28 symbols. When instantiating \class{graph.data.file}, you not only
29 specify the file name, but also a mapping from columns to axis names
30 and other information the style might use (\emph{e.g.} data for error
31 bars for the symbol style).
33 While the graph is already created by that, we still need to perform a
34 write of the result into a file. Since the graph instance is a canvas,
35 we can just call its \method{writeEPSfile()} method.
36 \begin{verbatim}
37 g.writeEPSfile("graph")
38 \end{verbatim}
39 will create the file \file{graph.eps} as shown in
40 figure~\ref{fig:graph}.
42 \begin{figure}[ht]
43 \centerline{\includegraphics{graph}}
44 \caption{A minimalistic plot for the data from file \file{graph.dat}.}
45 \label{fig:graph}
46 \end{figure}
48 Instead of plotting data from a file, we could also use other data
49 sources like functions. The procedure would be as before, but we would
50 place different data into \method{plot()}:
51 \begin{verbatim}
52 g.plot(graph.data.function("y=x**2"))
53 \end{verbatim}
54 You can plot different data into a single graph by calling the
55 \method{plot()} several times. Thus the command above might just be
56 inserted before \method{writeEPSfile()} of the original example.
57 Note that a call to \method{plot()} will fail once you forced the
58 graph to ``finish'' itself. This happens automatically, when you
59 write the output. Thus it is not an option to call \method{plot()}
60 after \method{writeEPSfile()}. The topic of the finalization of a
61 graph is addressed in more detail in section~\ref{graph:graph}. As
62 you can see in figure~\ref{fig:graph2}, a function is plotted as a
63 line by default.
64 \begin{figure}[ht]
65 \centerline{\includegraphics{graph2}}
66 \caption{Plotting data from a file together with a function.}
67 \label{fig:graph2}
68 \end{figure}
70 \section{Component architecture \label{graph:components}}
72 Creating a graph involves a variety of tasks, which thus can be
73 separated into components without significant additional costs.
74 This structure manifests itself also in the \PyX{} source, where there
75 are different modules for the different tasks. They interact by some
76 welldefined interfaces. They certainly has to be completed and
77 stabilized in its details, but the basic structure came up in the
78 continuous development quite clearly. The basic parts of a graph are:
80 \begin{definitions}
81 \term{graph}
82 Defines the geometry of the graph by means of graph coordinates with
83 range [0:1]. Keeps lists of plotted data, axes \emph{etc.}
84 \term{data}
85 Produces or prepare data to be plotted in graphs.
86 \term{style}
87 Performs the plotting of the data into the graph. It get data,
88 convert them via the axes into graph coordinates and uses the graph
89 to finally plot the data with respect to the graph geometry methods.
90 \term{key}
91 Responsible for the graph keys.
92 \term{axis}
93 Creates axes for the graph, which take care of the mapping from data
94 values to graph coordinates. Because axes are also responsible for
95 creating ticks and labels, showing up in the graph themselfs and
96 other things, this task is splitted into several independend
97 subtasks. Axes are discussed separately in chapter~\ref{axis}.
98 \end{definitions}
100 \section{X-Y-Graphs\label{graph:graph}}
102 \declaremodule{}{graph.graph}
103 \modulesynopsis{Graph geometry}
105 The class \class{graphxy} is part of the module \module{graph.graph}.
106 However, there is a shortcut to access this class via
107 \code{graph.graphxy}.
109 \begin{classdesc}{graphxy}{xpos=0, ypos=0, width=None, height=None,
110 ratio=goldenmean, key=None, backgroundattrs=None, axesdist="0.8 cm",
111 **axes}
112 This class provides a x-y-graph. A graph instance is also a full
113 functional canvas.
115 The position of the graph on its own canvas is specified by
116 \var{xpos} and \var{ypos}. The size of the graph is specified by
117 \var{width}, \var{height}, and \var{ratio}. These parameters define
118 the size of the graph area not taking into account the additional
119 space needed for the axes. Note that you have to specify at least
120 \var{width} or \var{height}. \var{ratio} will be used as the ratio
121 between \var{width} and \var{height} when only one of these are
122 provided.
124 \var{key} can be set to a \class{graph.key.key} instance to create
125 an automatic graph key. \code{None} omits the graph key.
127 \var{backgroundattrs} is a list of attributes for drawing the
128 background of the graph. Allowed are decorators, strokestyles, and
129 fillstyles. \code{None} disables background drawing.
131 \var{axisdist} is the distance between axes drawn at the same side
132 of a graph.
134 \var{**axes} recieves axes instances. Allowed keywords (axes names)
135 are \code{x}, \code{x2}, \code{x3}, \emph{etc.} and \code{y},
136 \code{y2}, \code{y3}, \emph{etc.} When not providing a \code{x} or
137 \code{y} axis, linear axes instances will be used automatically.
138 When not providing a \code{x2} or \code{y2} axis, linked axes to the
139 \code{x} and \code{y} axes are created automatically. You may set
140 those axes to \code{None} to disable the automatic creation of axes.
141 The even numbered axes are plotted at the top (\code{y} axes) and
142 right (\code{x} axes) while the others are plotted at the bottom
143 (\code{x} axes) and left (\code{y} axes) in ascending order each.
144 Axes instances should be used once only.
145 \end{classdesc}
147 Some instance attributes might be usefull for outside read-access.
148 Those are:
150 \begin{memberdesc}{axes}
151 A dictionary mapping axes names to the \class{axis} instances.
152 \end{memberdesc}
154 \begin{memberdesc}{axespos}
155 A dictionary mapping axes names to the \class{axispos} instances.
156 \end{memberdesc}
158 To actually plot something into the graph, the following instance
159 method \method{plot()} is provided:
161 \begin{methoddesc}{plot}{data, style=None}
162 Adds \var{data} to the list of data to be plotted. Sets \var{style}
163 the be used for plotting the data. When \var{style} is \code{None},
164 the default style for the data as provided by \var{data} is used.
166 \var{data} should be an instance of any of the data described in
167 section~\ref{graph:data}. This instance should used once only.
169 When a style is used several times within the same graph instance,
170 it is kindly asked by the graph to iterate its appearence. Its up
171 to the style how this is performed.
173 Instead of calling the plot method several times with different
174 \var{data} but the same style, you can use a list (or something
175 iterateable) for \var{data}.
176 \end{methoddesc}
178 While a graph instance only collects data initially, at a certain
179 point it must create the whole plot. Once this is done, further calls
180 of \method{plot()} will fail. Usually you do not need to take care
181 about the finalization of the graph, because it happens automatically
182 once you write the plot into a file. However, sometime position
183 methods (described below) are nice to be accessable. For that, at
184 least the layout of the graph must be done. By calling the
185 \method{do}-methods yourself you can also alter the order in which
186 the graph is plotted. Multiple calls the any of the
187 \method{do}-methods have no effect (only the first call counts). The
188 orginal order in which the \method{do}-methods are called is:
190 \begin{methoddesc}{dolayout}{}
191 Fixes the layout of the graph. As part of this work, the ranges of
192 the axes are fitted to the data when the axes ranges are allowed to
193 addjust themselfs to the data ranges. The other \method{do}-methods
194 ensure, that this method is always called first.
195 \end{methoddesc}
197 \begin{methoddesc}{dobackground}{}
198 Draws the background.
199 \end{methoddesc}
201 \begin{methoddesc}{doaxes}{}
202 Inserts the axes.
203 \end{methoddesc}
205 \begin{methoddesc}{dodata}{}
206 Plots the data.
207 \end{methoddesc}
209 \begin{methoddesc}{dokey}{}
210 Inserts the graph key.
211 \end{methoddesc}
213 The graph provides some methods to access its geometry:
215 \begin{methoddesc}{pos}{x, y, xaxis=None, yaxis=None}
216 Returns the given point at \var{x} and \var{y} as a tuple
217 \code{(xpos, ypos)} at the graph canvas. \var{x} and \var{y} are
218 axis data values for the two axes \var{xaxis} and \var{yaxis}. When
219 \var{xaxis} or \var{yaxis} are \code{None}, the axes with names
220 \code{x} and \code{y} are used. This method fails if called before
221 \method{dolayout()}.
222 \end{methoddesc}
224 \begin{methoddesc}{vpos}{vx, vy}
225 Returns the given point at \var{vx} and \var{vy} as a tuple
226 \code{(xpos, ypos)} at the graph canvas. \var{vx} and \var{vy} are
227 graph coordinates with range [0:1].
228 \end{methoddesc}
230 \begin{methoddesc}{vgeodesic}{vx1, vy1, vx2, vy2}
231 Returns the geodesic between points \var{vx1}, \var{vy1} and
232 \var{vx1}, \var{vy1} as a path. All parameters are in graph
233 coordinates with range [0:1]. For \class{graphxy} this is a straight
234 line.
235 \end{methoddesc}
237 \begin{methoddesc}{vgeodesic\_el}{vx1, vy1, vx2, vy2}
238 Like \method{vgeodesic()} but this method returns the path element to
239 connect the two points.
240 \end{methoddesc}
242 \section{Data\label{graph:data}}
244 \declaremodule{}{graph.data}
245 \modulesynopsis{Graph data}
247 The following classes provide data for the \method{plot()} method of a
248 graph. The classes are implemented in \module{graph.data}.
250 \begin{classdesc}{file}{filename,
251 commentpattern=defaultcommentpattern,
252 columnpattern=defaultcolumnpattern,
253 stringpattern=defaultstringpattern,
254 skiphead=0, skiptail=0, every=1, title=notitle,
255 parser=dataparser(), context=\{\}, **columns}
256 This class reads data from a file and makes them available to the
257 graph system. \var{filename} is the name of the file to be read.
258 The data should be organized in columns.
260 The arguments \var{commentpattern}, \var{columnpattern}, and
261 \var{stringpattern} are responsible for identifying the data in each
262 line of the file. Lines matching \var{commentpattern} are ignored
263 except for the column name search of the last non-emtpy comment line
264 before the data. By default a line starting with one of the
265 characters \character{\#}, \character{\%}, or \character{!} are
266 treated as comments. A line is analysed by repeatingly matching
267 \var{stringpattern} and, whenever the stringpattern does not match
268 by \var{columnpattern}. When the \var{stringpattern} matches, the
269 result is taken as the value for the next column without further
270 transformations. When \var{columnpattern} matches, it is tried to
271 convert the result to a float. When this fails the result is taken
272 as a string as well. By default, you can write strings with spaces
273 surrounded by \character{\textquotedbl} immediately surrounded by
274 spaces or begin/end of line in the data file. Otherwise
275 \character{\textquotedbl} is not taken to be special.
277 \var{skiphead} and \var{skipfoot} are numbers of data lines to be
278 ignored at the beginning and end of the file while \var{every}
279 selects only every \var{every} line from the data.
281 \var{title} is the title of the data to be used in the graph key. A
282 default title is constructed out of \var{filename} and
283 \var{**columns}. You may set \var{title} to \code{None} to disable
284 the title.
286 \var{parser} is the parser for mathematical expression provided in
287 \var{**columns}. When in doubt, this is probably uninteresting for
288 you. \var{context} allows for accessing external variables and
289 functions when evaluating mathematical expressions for columns. As
290 an example you may use \code{context=locals()} or something similar.
292 Finally, \var{columns} defines the data columns. To make it a bit
293 more complicated, there are file column names and new created data
294 column names, namely the keywords of \var{**columns}. File column
295 names occure when the data file contains a comment line immediately
296 in front of the data. This line will be parsed skipping the comment
297 character (even if it occures multiple times) as if it would be
298 regular data, but it will not be converted to floats even if it
299 would be possible to convert them. The values of \var{**columns} can
300 refer to column numbers in the file (starting with \code{1}). The
301 column \code{0} is also available and contains the line number
302 starting from \code{1} not counting comment lines. Furthermore
303 values of \var{**columns} can be strings: file column names or
304 mathematical expressions. To refer to columns within mathematical
305 expressions you can also use file column names when they are valid
306 variable names or by the syntax \code{\$\textless
307 number\textgreater} or even \code{\$(\textless
308 expression\textgreater)}, where \code{\textless number\textgreater}
309 is a non-negative integer and \code{\textless
310 expression\textgreater} a valid mathematical expression itself. For
311 the later negative numbers count the columns from the end.
312 Example:
313 \begin{verbatim}
314 graph.data.file("test.dat", a=1, b="B", c="2*B+$3")
315 \end{verbatim}
316 with \file{test.dat} looking like:
317 \begin{verbatim}
318 # A B C
319 1.234 1 2
320 5.678 3 4
321 \end{verbatim}
322 The columns with name \samp{a}, \samp{b}, \samp{c} will become
323 \samp{[1.234, 5.678]}, \samp{[1.0, 3.0]}, and \samp{[4.0, 10.0]},
324 respectively.
326 When creating the several data instances accessing the same file,
327 the file is read only once. There is an inherent caching of the
328 file contents.
329 \end{classdesc}
331 For the sake of completeness the default patterns:
333 \begin{memberdesc}{defaultcommentpattern}
334 \code{re.compile(r\textquotedbl (\#+|!+|\%+)\e s*\textquotedbl)}
335 \end{memberdesc}
337 \begin{memberdesc}{defaultcolumnpattern}
338 \code{re.compile(r\textquotedbl\e \textquotedbl(.*?)\e \textquotedbl(\e s+|\$)\textquotedbl)}
339 \end{memberdesc}
341 \begin{memberdesc}{defaultstringpattern}
342 \code{re.compile(r\textquotedbl(.*?)(\e s+|\$)\textquotedbl)}
343 \end{memberdesc}
345 \begin{classdesc}{function}{expression, title=notitle,
346 min=None, max=None, points=100,
347 parser=mathtree.parser(),
348 context=\{\}}
349 This class creates graph data from a function. \var{expression} is
350 the mathematical expression of the function. It must also contain
351 the result variable name by assignment. Thus a typical example looks
352 like \samp{y=sin(x)}.
354 \var{title} is the title of the data to be used in the graph key. By
355 default \var{expression} is used. You may set \var{title} to
356 \code{None} to disable the title.
358 \var{min} and \var{max} give the range of the variable. If not set
359 the range spans the hole axis range. The axis range might be set
360 explicitly or implicitly by ranges of other data. \var{points} is
361 the number of points for which the function is calculated. The
362 points are lineary choosen in terms of graph coordinates.
364 \var{parser} is the parser for the mathematical expression. When in
365 doubt, this is probably uninteresting for you. \var{context} allows
366 for accessing external variables and functions. As an example you
367 may use \code{context=locals()} or something similar.
369 Note when accessing external variables: When doing so, at first it
370 renders unclear, which of the variables should be used as the
371 dependent variable. The solution is, that there should be exactly
372 one variable, which is a valid and used axis name.
373 Example:
374 \begin{verbatim}
375 [graph.data.function("y=x**i", context=locals()) for i in range(1, 5)]
376 \end{verbatim}
377 The result of this expression could just be passed to a graphs
378 \method{plot()} method, since not only data instances but also lists
379 of data instances are allowed.
380 \end{classdesc}
382 \begin{classdesc}{paramfunction}{varname, min, max, expression,
383 title=notitle, points=100,
384 parser=mathtree.parser(),
385 context=\{\}}
386 This class creates graph data from a parametric function.
387 \var{varname} is the parameter of the function. \var{min} and
388 \var{max} give the range for that variable. \var{points} is the
389 number of points for which the function is calculated. The points
390 are choosen lineary in terms of the parameter.
392 \var{expression} is the mathematical expression for the parametric
393 function. It contains an assignment of a tuple of functions to a
394 tuple of variables.
396 \var{title} is the title of the data to be used in the graph key. By
397 default \var{expression} is used. You may set \var{title} to
398 \code{None} to disable the title.
400 \var{parser} is the parser for mathematical expression. When in
401 doubt, this is probably uninteresting for you. \var{context} allows
402 for accessing external variables and functions. As an example you
403 may use \code{context=locals()} or something similar.
404 \end{classdesc}
406 \begin{classdesc}{list}{points, title="user provided list",
407 maxcolumns=None, addlinenumbers=1, **columns}
408 This class creates graph data from external provided data.
409 \var{points} is a list of lines, where each line is a list of data
410 values for the columns.
412 \var{title} is the title of the data to be used in the graph key.
414 \var{maxcolumn} is the number of columns in the points list. If set
415 to \code{None}, the number of columns will be calculated by cycling
416 through the points. Each element of \var{points}, \emph{i.e.} each
417 line, will be checked and adjusted to the number of columns.
419 \var{addlinenumbers} is a boolean indicating whether line numbers
420 should be added or not. Note that the line numbers are storred in
421 column \code{0}. A transformation (see \class{data} below) will
422 always keep the first column. When not adding line numbers, you
423 should be aware, that the numbering in \var{**columns} becomes
424 different form the usual case, where the first column containing
425 data (not the line number) has column number \code{1}.
427 The keywords of \var{**columns} become the data column names. The
428 values are the column numbers starting from one, when
429 \var{addlinenumbers} is turned on (the zeroth column is the line
430 number then), while the column numbers starts from zero, when
431 \var{addlinenumbers} is switched off.
432 \end{classdesc}
434 \begin{classdesc}{data}{data, title=notitle, parser=dataparser(),
435 context={}, **columns}
436 This class provides graph data out of other graph data. \var{data}
437 is the source of the data. All other paramters work like the equally
438 called parameters in \class{graph.data.file}. Indeed, the later is
439 build on top of this class by reading the file and caching its
440 contents in a \class{graph.data.list} instance. The columns are then
441 selected by creating new data out of the existing data. Note that
442 the data itself is not copied as long as no new columns need to be
443 calculated.
444 \end{classdesc}
446 \begin{classdesc}{conffile}{filename, title=notitle,
447 parser=dataparser(), context={},
448 **columns}
449 This class reads data from a config file with the file name
450 \var{filename}. The format of a config file is described within the
451 documentation of the \module{ConfigParser} module of the Python
452 Standard Library.
454 Each section of the config file becomes a data line. The options in
455 a section are the columns. The name of the options will be used as
456 file column names. All other parameters work as in
457 \var{graph.data.file} and \var{graph.data.data} since they all use
458 the same code.
459 \end{classdesc}
461 \section{Styles\label{graph:style}}
463 \declaremodule{}{graph.style}
464 \modulesynopsis{Graph style}
466 Please note that we're talking about graph styles here. Those are
467 responsible for plotting symbols, lines, bars and whatever else into a
468 graph. Do not mix it up with path styles like the line width, the line
469 style (solid, dashed, dotted \emph{etc.}) and others.
471 The following classes provide styles to be used at the \method{plot()}
472 method of a graph. The classes are implemented in \module{graph.style}.
474 \begin{classdesc}{symbolline}{symbol=changecross, size="0.2 cm",
475 errorscale=0.5, symbolattrs=[],
476 errorbarattrs=[], lineattrs=[],
477 epsilon=1e-10}
478 This class is a style for plot symbols, lines and errorbars into a
479 graph. \var{symbol} refers to a (changable) symbol method (see
480 below). The symbol is drawn at size \var{size} (a visual \PyX{}
481 length; also changeable) using \var{symbolattrs}. \var{symbolattrs}
482 are merged with the decorator \class{deco.stroked}. \var{errorscale}
483 is the size of the error bars compared to the symbol size.
484 \var{errorbarattrs} and \var{lineattrs} are strokestyles for
485 stroking the errorbars and lines, respecively. \var{lineattrs} are
486 merged with \var{changelinestyle} (see below). \var{epsilon} is used
487 to determine, when a symbol is outside of the graph (in graph
488 coordinates).
490 \var{symbolline} is useable on graphs with arbitrary dimension and
491 geometry. It needs one data column for each graph dimension. The
492 data names must be equal to an axis name. Furthermore there can be
493 data names constructed out of the axis names for identifying data
494 for the error bars. Suppose \code{X} is an axis name. Then
495 \class{symbolline} allows for the following data names as well:
497 \begin{tableii}{l|l}{}{data name}{description}
498 \lineii{\code{Xmin}}{minimal value}
499 \lineii{\code{Xmax}}{maximal value}
500 \lineii{\code{Xd}}{minimal and maximal delta}
501 \lineii{\code{Xdmin}}{minimal delta}
502 \lineii{\code{Xdmax}}{maximal delta}
503 \end{tableii}
505 Minimal and maximal values are calculated from delta by subtracting
506 and adding it to the value itself. Most of the data names are mutal
507 exclusive (whenever a minimal or maximal value would be set twice).
508 \end{classdesc}
510 \class{symbolline} provides some symbol methods, namely:
512 \begin{methoddesc}{cross}{x_pt, y_pt, size_pt}
513 A cross. Should be used for stroking only.
514 \end{methoddesc}
516 \begin{methoddesc}{plus}{x_pt, y_pt, size_pt}
517 A plus. Should be used for stroking only.
518 \end{methoddesc}
520 \begin{methoddesc}{square}{x_pt, y_pt, size_pt}
521 A square. Might be stroked or filled or both.
522 \end{methoddesc}
524 \begin{methoddesc}{triangle}{x_pt, y_pt, size_pt}
525 A triangle. Might be stroked or filled or both.
526 \end{methoddesc}
528 \begin{methoddesc}{circle}{x_pt, y_pt, size_pt}
529 A circle. Might be stroked or filled or both.
530 \end{methoddesc}
532 \begin{methoddesc}{diamond}{x_pt, y_pt, size_pt}
533 A diamond. Might be stroked or filled or both.
534 \end{methoddesc}
536 \class{symbolline} provides some changeable symbol methods as class
537 variables, namely:
539 \begin{memberdesc}{changecross}
540 attr.changelist([cross, plus, square, triangle, circle, diamond])
541 \end{memberdesc}
543 \begin{memberdesc}{changeplus}
544 attr.changelist([plus, square, triangle, circle, diamond, cross])
545 \end{memberdesc}
547 \begin{memberdesc}{changesquare}
548 attr.changelist([square, triangle, circle, diamond, cross, plus])
549 \end{memberdesc}
551 \begin{memberdesc}{changetriangle}
552 attr.changelist([triangle, circle, diamond, cross, plus, square])
553 \end{memberdesc}
555 \begin{memberdesc}{changecircle}
556 attr.changelist([circle, diamond, cross, plus, square, triangle])
557 \end{memberdesc}
559 \begin{memberdesc}{changediamond}
560 attr.changelist([diamond, cross, plus, square, triangle, circle])
561 \end{memberdesc}
563 \begin{memberdesc}{changesquaretwice}
564 attr.changelist([square, square, triangle, triangle, circle, circle, diamond, diamond])
565 \end{memberdesc}
567 \begin{memberdesc}{changetriangletwice}
568 attr.changelist([triangle, triangle, circle, circle, diamond, diamond, square, square])
569 \end{memberdesc}
571 \begin{memberdesc}{changecircletwice}
572 attr.changelist([circle, circle, diamond, diamond, square, square, triangle, triangle])
573 \end{memberdesc}
575 \begin{memberdesc}{changediamondtwice}
576 attr.changelist([diamond, diamond, square, square, triangle, triangle, circle, circle])
577 \end{memberdesc}
579 \class{symbolline} provides two changeable decorators for alternated filling
580 and stroking. Those are especially usefull in combination with the
581 \method{change}-\method{twice}-symbol methods above. They are:
583 \begin{memberdesc}{changestrokedfilled}
584 attr.changelist([deco.stroked, deco.filled])
585 \end{memberdesc}
587 \begin{memberdesc}{changefilledstroked}
588 attr.changelist([deco.filled, deco.stroked])
589 \end{memberdesc}
591 Finally, there is a changeable linestyle used by default. It is
592 defined as:
594 \begin{memberdesc}{changelinestyle}
595 attr.changelist([style.linestyle.solid, style.linestyle.dashed, style.linestyle.dotted, style.linestyle.dashdotted])
596 \end{memberdesc}
598 \begin{classdesc}{symbol}{symbol=changecross, size="0.2 cm",
599 errorscale=0.5, symbolattrs=[],
600 errorbarattrs=[], epsilon=1e-10}
601 This class is a style to plot symbols and errorbars into a graph. It
602 is equivalent to \class{symbollines} except that it does not allow
603 for lines. An instance of \class{symbol} is the default style for
604 all data classes described in section~\ref{graph:data} except for
605 \class{function} and \class{paramfunction}.
606 \end{classdesc}
608 \begin{classdesc}{line}{errorbarattrs=[]}
609 This class is a style to stroke lines into graph. It is equivalent
610 to \class{symbollines} except that it does not allow for symbols and
611 errorbars. Thus it also does not accept data names for error bars.
612 Instances of \class{line} are the default style for the data classes
613 \class{function} and \class{paramfunction}.
614 \end{classdesc}
616 \begin{classdesc}{text}{textdx="0", textdy="0.3 cm", textattrs=[],
617 symbol=changecross, size="0.2 cm",
618 errorscale=0.5, symbolattrs=[],
619 errorbarattrs=[], epsilon=1e-10}
620 This class enhances \class{symbol} by adding text to the symbol. The
621 text to be written has provided in the additional data column named
622 \code{text}. \var{textdx} and \var{textdy} are the position of the
623 text with respect of the symbol. \var{textattrs} are text
624 attributes for the output of the text. All other parameters have the
625 same meaning as in the \class{symbol} class.
626 \end{classdesc}
628 \begin{classdesc}{arrow}{linelength="0.25 cm", arrowsize="0.15 cm",
629 lineattrs=[], arrowattrs=[], epsilon=1e-10}
630 This class is a style to plot short lines with arrows into a
631 two-dimensional graph. The position of the arrow is defined by two
632 data columns named like an axes for each graph dimension. Two
633 additional data columns named \code{size} and \code{angle} define
634 the size and angle for each arrow. \code{size} is taken as a factor
635 to \var{arrowsize} and \var{linelength}, the size of the arrow and
636 the length of the line the arrow is plotted at. \code{angle} is the
637 angle the arrow points to with respect to a horizonal lines. The
638 \code{angle} is taken in degree and use in mathematical positive
639 sense. \var{lineattrs} and \var{arrowattrs} are styles for the arrow
640 line and arrow head respectively. \var{epsilon} is used to
641 determine, when the arrow is outside of the graph (in graph
642 coordinates).
643 \end{classdesc}
645 \begin{classdesc}{rect}{palette=color.palette.Gray}
646 This class is a style to plot coloured rectangles into a
647 two-dimensional graph. The position of the rectangles are given by 4
648 data columns named \code{Xmin} and \code{Xmax} where \code{X} stands
649 for two axes names, one for each graph dimension. The additional
650 data column named \code{color} specifies the color of the rectangle
651 defined by \var{palette}. Thus the valid color range is [0:1].
653 \begin{note}
654 Although this style can be used for plotting coloured surfaces, it
655 will lead to a huge memory footprint of \PyX together with a
656 long running time and large outputs. Improved support for coloured
657 surfaces are planned for the future.
658 \end{note}
659 \end{classdesc}
661 \begin{classdesc}{bar}{fromvalue=None, frompathattrs=[], barattrs=[],
662 subnames=None, epsilon=1e-10}
663 This class is a style to plot bars into a two-dimensional graph. The
664 bars are plotted on top of a specialized axis, namely a bar axis.
665 The data column for this bar axis is named \code{Xname} where
666 \code{X} is an axis name. The bar value have a name an axis of the
667 other graph dimension. Suppose the name of this value axis is
668 \code{Y} than you can stack further bars on top of this bar by
669 providing additional data columns consecutively named
670 \code{Ystack1}, \code{Ystack2}, \code{Ystack3}, \emph{etc.}
671 When plotting several bars in a single graph, those bars are placed
672 side by side (at the same value of \code{Xname}). The name axis, a
673 bar axis, must then be a nested bar axis. The names used for the
674 subaxis can be set by \var{subnames}. When not set, integer numbers
675 starting from zero will be used.
677 The bars start at \var{fromvalue} when provided. The \var{fromvalue}
678 is marked by a gridline stroked using \var{frompathattrs}. The bars
679 are filled using \var{barattrs}. \var{barattrs} is merged with
680 \samp{[color.palette.Rainbow, deco.stroked([color.gray.black])]} and
681 iterated independently when several bars are plotted side by side
682 and when several bars are plotted on top of each other. When mixing
683 both possibilities, you may use nested changeable styles.
684 \end{classdesc}
686 \section{Keys\label{graph:key}}
688 \declaremodule{}{graph.key}
689 \modulesynopsis{Graph keys}
691 The following class provides a key, whose instances can be passed to
692 the constructor keyword argument \code{key} of a graph. The class is
693 implemented in \module{graph.key}.
695 \begin{classdesc}{key}{dist="0.2 cm", pos="tr", hinside=1, vinside=1,
696 hdist="0.6 cm", vdist="0.4 cm",
697 symbolwidth="0.5 cm", symbolheight="0.25 cm",
698 symbolspace="0.2 cm", textattrs=[]}
699 This class writes the title of the data in a plot together with a
700 small illustration of the style. The style is responsible for its
701 illustration.
703 \var{dist} is a visual length and a distance between the key
704 entries. \var{pos} is the position of the key with respect to the
705 graph. Allowed values are combinations of \samp{t} (top) and
706 \samp{b} (bottom) with \samp{l} (left) and \samp{r} (right).
707 \var{hdist} and \var{vdist} are the distances from the specified
708 corner of the graph. \var{hinside} and \var{vinside} are booleans to
709 define whether the key should be placed horizontally and vertically
710 inside of the graph or not.
712 \var{symbolwidth} and \var{symbolheight} is passed to the style to
713 control the size of the style illustration. \var{symbolspace} is the
714 space between the illustration and the text. \var{textattrs} are
715 attributes for the text creation. They are merged with
716 \samp{[text.vshift.mathaxis]}.
717 \end{classdesc}