test trafo application in draw
[PyX/mjg.git] / manual / graph.tex
blob75023ea6e75a8179996d6e484207b0364e6477fe
1 \chapter{Graphs}
2 \label{graph}
3 \section{Introduction}
4 \PyX{} can be used for data and function plotting. At present only
5 x-y-graphs are supported. However, the component architecture of the
6 graph system described in section \ref{graph:components} allows for
7 additional graph geometries while reusing most of the existing
8 components.
10 Creating a graph splits into two basic steps. First you have to create
11 a graph instance. The most simple form would look like:
12 \begin{verbatim}
13 from pyx import *
14 g = graph.graphxy(width=8)
15 \end{verbatim}
16 The graph instance \code{g} created in this example can then be used
17 to actually plot something into the graph. Suppose you have some data
18 in a file \file{graph.dat} you want to plot. The content of the file
19 could look like:
20 \verbatiminput{graph.dat}
21 To plot these data into the graph \code{g} you must perform:
22 \begin{verbatim}
23 g.plot(graph.data.file("graph.dat", x=1, y=2))
24 \end{verbatim}
25 The method \method{plot()} takes the data to be plotted and optionally
26 a list of graph styles to be used to plot the data. When no styles are
27 provided, a default style defined by the data instance is used. For
28 data read from a file by an instance of \class{graph.data.file}, the
29 default are symbols. When instantiating \class{graph.data.file}, you
30 not only specify the file name, but also a mapping from columns to
31 axis names and other information the styles might make use of
32 (\emph{e.g.} data for error bars to be used by the errorbar style).
34 While the graph is already created by that, we still need to perform a
35 write of the result into a file. Since the graph instance is a canvas,
36 we can just call its \method{writeEPSfile()} method.
37 \begin{verbatim}
38 g.writeEPSfile("graph")
39 \end{verbatim}
40 The result \file{graph.eps} is shown in 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, other data source are available
49 as well. For example function data is created and placed into
50 \method{plot()} by the following line:
51 \begin{verbatim}
52 g.plot(graph.data.function("y=x**2"))
53 \end{verbatim}
54 You can plot different data in a single graph by calling
55 \method{plot()} several times before \method{writeEPSfile()}. Note
56 that a calling \method{plot()} will fail once a graph was forced to
57 ``finish'' itself. This happens automatically, when the graph is
58 written to a file. Thus it is not an option to call \method{plot()}
59 after \method{writeEPSfile()}. The topic of the finalization of a
60 graph is addressed in more detail in section~\ref{graph:graph}. As you
61 can see in figure~\ref{fig:graph2}, a function is plotted as a line by
62 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 While the axes ranges got adjusted automatically in the previous
71 example, they might be fixed by keyword options in axes constructors.
72 Plotting only a function will need such a setting at least in the
73 variable coordinate. The following code also shows how to set a
74 logathmic axis in y-direction:
76 \verbatiminput{graph3.py}
78 The result is shown in figure~\ref{fig:graph3}.
80 \begin{figure}[ht]
81 \centerline{\includegraphics{graph3}}
82 \caption{Plotting a function for a given axis range and use a
83 logarithmic y-axis.}
84 \label{fig:graph3}
85 \end{figure}
87 \section{Component architecture}
88 \label{graph:components}
90 Creating a graph involves a variety of tasks, which thus can be
91 separated into components without significant additional costs.
92 This structure manifests itself also in the \PyX{} source, where there
93 are different modules for the different tasks. They interact by some
94 well-defined interfaces. They certainly have to be completed and
95 stabilized in their details, but the basic structure came up in the
96 continuous development quite clearly. The basic parts of a graph are:
98 \begin{definitions}
99 \term{graph}
100 Defines the geometry of the graph by means of graph coordinates with
101 range [0:1]. Keeps lists of plotted data, axes \emph{etc.}
102 \term{data}
103 Produces or prepares data to be plotted in graphs.
104 \term{style}
105 Performs the plotting of the data into the graph. It gets data,
106 converts them via the axes into graph coordinates and uses the graph
107 to finally plot the data with respect to the graph geometry methods.
108 \term{key}
109 Responsible for the graph keys.
110 \term{axis}
111 Creates axes for the graph, which take care of the mapping from data
112 values to graph coordinates. Because axes are also responsible for
113 creating ticks and labels, showing up in the graph themselves and
114 other things, this task is splitted into several independent
115 subtasks. Axes are discussed separately in chapter~\ref{axis}.
116 \end{definitions}
118 \section{Module \code{graph/graph}: X-Y-Graphs}
119 \label{graph:graph}
121 \declaremodule{}{graph.graph}
122 \modulesynopsis{Graph geometry}
124 The class \class{graphxy} is part of the module \module{graph.graph}.
125 However, there is a shortcut to access this class via
126 \code{graph.graphxy}.
128 \begin{classdesc}{graphxy}{xpos=0, ypos=0, width=None, height=None,
129 ratio=goldenmean, key=None, backgroundattrs=None, axesdist="0.8 cm",
130 **axes}
131 This class provides an x-y-graph. A graph instance is also a fully
132 functional canvas.
134 The position of the graph on its own canvas is specified by
135 \var{xpos} and \var{ypos}. The size of the graph is specified by
136 \var{width}, \var{height}, and \var{ratio}. These parameters define
137 the size of the graph area not taking into account the additional
138 space needed for the axes. Note that you have to specify at least
139 \var{width} or \var{height}. \var{ratio} will be used as the ratio
140 between \var{width} and \var{height} when only one of these is
141 provided.
143 \var{key} can be set to a \class{graph.key.key} instance to create
144 an automatic graph key. \code{None} omits the graph key.
146 \var{backgroundattrs} is a list of attributes for drawing the
147 background of the graph. Allowed are decorators, strokestyles, and
148 fillstyles. \code{None} disables background drawing.
150 \var{axisdist} is the distance between axes drawn at the same side
151 of a graph.
153 \var{**axes} receives axes instances. Allowed keywords (axes names)
154 are \code{x}, \code{x2}, \code{x3}, \emph{etc.} and \code{y},
155 \code{y2}, \code{y3}, \emph{etc.} When not providing an \code{x} or
156 \code{y} axis, linear axes instances will be used automatically.
157 When not providing a \code{x2} or \code{y2} axis, linked axes to the
158 \code{x} and \code{y} axes are created automatically. You may set
159 those axes to \code{None} to disable the automatic creation of axes.
160 The even numbered axes are plotted at the top (\code{x} axes) and
161 right (\code{y} axes) while the others are plotted at the bottom
162 (\code{x} axes) and left (\code{y} axes) in ascending order each.
163 Axes instances should only be used once.
164 \end{classdesc}
166 Some instance attributes might be useful for outside read-access.
167 Those are:
169 \begin{memberdesc}{axes}
170 A dictionary mapping axes names to the \class{axis} instances.
171 \end{memberdesc}
173 \begin{memberdesc}{axespos}
174 A dictionary mapping axes names to the \class{axispos} instances.
175 \end{memberdesc}
177 To actually plot something into the graph, the following instance
178 method \method{plot()} is provided:
180 \begin{methoddesc}{plot}{data, styles=None}
181 Adds \var{data} to the list of data to be plotted. Sets \var{styles}
182 to be used for plotting the data. When \var{styles} is \code{None},
183 the default styles for the data as provided by \var{data} is used.
185 \var{data} should be an instance of any of the data described in
186 section~\ref{graph:data}. This instance should only be used once.
188 When the same combination of styles (\emph{i.e.} the same
189 references) are used several times within the same graph instance,
190 the styles are kindly asked by the graph to iterate their
191 appearence. Its up to the styles how this is performed.
193 Instead of calling the plot method several times with different
194 \var{data} but the same style, you can use a list (or something
195 iterateable) for \var{data}.
196 \end{methoddesc}
198 While a graph instance only collects data initially, at a certain
199 point it must create the whole plot. Once this is done, further calls
200 of \method{plot()} will fail. Usually you do not need to take care
201 about the finalization of the graph, because it happens automatically
202 once you write the plot into a file. However, sometimes position
203 methods (described below) are nice to be accessible. For that, at
204 least the layout of the graph must have been finished. By calling the
205 \method{do}-methods yourself you can also alter the order in which the
206 graph components are plotted. Multiple calls to any of the
207 \method{do}-methods have no effect (only the first call counts). The
208 orginal order in which the \method{do}-methods are called is:
210 \begin{methoddesc}{dolayout}{}
211 Fixes the layout of the graph. As part of this work, the ranges of
212 the axes are fitted to the data when the axes ranges are allowed to
213 adjust themselves to the data ranges. The other \method{do}-methods
214 ensure, that this method is always called first.
215 \end{methoddesc}
217 \begin{methoddesc}{dobackground}{}
218 Draws the background.
219 \end{methoddesc}
221 \begin{methoddesc}{doaxes}{}
222 Inserts the axes.
223 \end{methoddesc}
225 \begin{methoddesc}{dodata}{}
226 Plots the data.
227 \end{methoddesc}
229 \begin{methoddesc}{dokey}{}
230 Inserts the graph key.
231 \end{methoddesc}
233 \begin{methoddesc}{finish}{}
234 Finishes the graph by calling all pending \method{do}-methods. This
235 is done automatically, when the output is created.
236 \end{methoddesc}
238 The graph provides some methods to access its geometry:
240 \begin{methoddesc}{pos}{x, y, xaxis=None, yaxis=None}
241 Returns the given point at \var{x} and \var{y} as a tuple
242 \code{(xpos, ypos)} at the graph canvas. \var{x} and \var{y} are
243 axis data values for the two axes \var{xaxis} and \var{yaxis}. When
244 \var{xaxis} or \var{yaxis} are \code{None}, the axes with names
245 \code{x} and \code{y} are used. This method fails if called before
246 \method{dolayout()}.
247 \end{methoddesc}
249 \begin{methoddesc}{vpos}{vx, vy}
250 Returns the given point at \var{vx} and \var{vy} as a tuple
251 \code{(xpos, ypos)} at the graph canvas. \var{vx} and \var{vy} are
252 graph coordinates with range [0:1].
253 \end{methoddesc}
255 \begin{methoddesc}{vgeodesic}{vx1, vy1, vx2, vy2}
256 Returns the geodesic between points \var{vx1}, \var{vy1} and
257 \var{vx2}, \var{vy2} as a path. All parameters are in graph
258 coordinates with range [0:1]. For \class{graphxy} this is a straight
259 line.
260 \end{methoddesc}
262 \begin{methoddesc}{vgeodesic\_el}{vx1, vy1, vx2, vy2}
263 Like \method{vgeodesic()} but this method returns the path element to
264 connect the two points.
265 \end{methoddesc}
267 % dirty hack to add a whole list of methods to the index:
268 \index{xbasepath()@\texttt{xbasepath()} (graphxy method)}
269 \index{xvbasepath()@\texttt{xvbasepath()} (graphxy method)}
270 \index{xgridpath()@\texttt{xgridpath()} (graphxy method)}
271 \index{xvgridpath()@\texttt{xvgridpath()} (graphxy method)}
272 \index{xtickpoint()@\texttt{xtickpoint()} (graphxy method)}
273 \index{xvtickpoint()@\texttt{xvtickpoint()} (graphxy method)}
274 \index{xtickdirection()@\texttt{xtickdirection()} (graphxy method)}
275 \index{xvtickdirection()@\texttt{xvtickdirection()} (graphxy method)}
276 \index{ybasepath()@\texttt{ybasepath()} (graphxy method)}
277 \index{yvbasepath()@\texttt{yvbasepath()} (graphxy method)}
278 \index{ygridpath()@\texttt{ygridpath()} (graphxy method)}
279 \index{yvgridpath()@\texttt{yvgridpath()} (graphxy method)}
280 \index{ytickpoint()@\texttt{ytickpoint()} (graphxy method)}
281 \index{yvtickpoint()@\texttt{yvtickpoint()} (graphxy method)}
282 \index{ytickdirection()@\texttt{ytickdirection()} (graphxy method)}
283 \index{yvtickdirection()@\texttt{yvtickdirection()} (graphxy method)}
285 Further geometry information is available by the \member{axespos}
286 instance variable. Shortcuts to the \class{axispos} methods for the
287 \code{x}- and \code{y}-axis become available after \method{dolayout()}
288 as \class{graphxy} methods \code{Xbasepath}, \code{Xvbasepath},
289 \code{Xgridpath}, \code{Xvgridpath}, \code{Xtickpoint},
290 \code{Xvtickpoint}, \code{Xtickdirection}, and \code{Xvtickdirection}
291 where the prefix \code{X} stands for \code{x} and \code{y}.
293 \section{Module \code{graph/data}: Data}
294 \label{graph:data}
296 \declaremodule{}{graph.data}
297 \modulesynopsis{Graph data}
299 The following classes provide data for the \method{plot()} method of a
300 graph. The classes are implemented in \module{graph.data}.
302 \begin{classdesc}{file}{filename,
303 commentpattern=defaultcommentpattern,
304 columnpattern=defaultcolumnpattern,
305 stringpattern=defaultstringpattern,
306 skiphead=0, skiptail=0, every=1, title=notitle,
307 parser=dataparser(), context=\{\}, **columns}
308 This class reads data from a file and makes them available to the
309 graph system. \var{filename} is the name of the file to be read.
310 The data should be organized in columns.
312 The arguments \var{commentpattern}, \var{columnpattern}, and
313 \var{stringpattern} are responsible for identifying the data in each
314 line of the file. Lines matching \var{commentpattern} are ignored
315 except for the column name search of the last non-emtpy comment line
316 before the data. By default a line starting with one of the
317 characters \character{\#}, \character{\%}, or \character{!} as well
318 as an empty line is treated as a comment.
320 A non-comment line is analysed by repeatedly matching
321 \var{stringpattern} and, whenever the stringpattern does not match,
322 by \var{columnpattern}. When the \var{stringpattern} matches, the
323 result is taken as the value for the next column without further
324 transformations. When \var{columnpattern} matches, it is tried to
325 convert the result to a float. When this fails the result is taken
326 as a string as well. By default, you can write strings with spaces
327 surrounded by \character{\textquotedbl} immediately surrounded by
328 spaces or begin/end of line in the data file. Otherwise
329 \character{\textquotedbl} is not taken to be special.
331 \var{skiphead} and \var{skiptail} are numbers of data lines to be
332 ignored at the beginning and end of the file while \var{every}
333 selects only every \var{every} line from the data.
335 \var{title} is the title of the data to be used in the graph key. A
336 default title is constructed out of \var{filename} and
337 \var{**columns}. You may set \var{title} to \code{None} to disable
338 the title.
340 \var{parser} is the parser for mathematical expressions provided in
341 \var{**columns}. When in doubt, this is probably uninteresting for
342 you. \var{context} allows for accessing external variables and
343 functions when evaluating mathematical expressions for columns. As
344 an example you may use \code{context=locals()} or something similar.
346 Finally, \var{columns} defines the data columns. To make it a bit
347 more complicated, there are file column names and new created data
348 column names, namely the keys of the dictionary \var{**columns}.
349 Only the later, the data column names, are valid identifiers for the
350 data columns at later usage (by the graph styles).
352 File column names occur when the data file contains a comment line
353 immediately in front of the data (except for empty or empty comment
354 lines). This line will be parsed skipping the matched comment
355 identifier as if the line would be regular data, but it will not be
356 converted to floats even if it would be possible to convert the
357 items. The result is taken as file column names, \emph{i.e.} a
358 string representation for the columns in the file.
360 The values of \var{**columns} can refer to column numbers in the
361 file starting at \code{1}. The column \code{0} is also available
362 and contains the line number starting from \code{1} not counting
363 comment lines, but lines skiped by \var{skiphead}, \var{skiptail},
364 and \var{every}. Furthermore values of \var{**columns} can be
365 strings: file column names or complex mathematical expressions. To
366 refer to columns within mathematical expressions you can also use
367 file column names when they are valid variable names or by the
368 syntax \code{\$\textless number\textgreater} or even
369 \code{\$(\textless expression\textgreater)}, where \code{\textless
370 number\textgreater} is a non-negative integer and \code{\textless
371 expression\textgreater} a valid mathematical expression itself. In
372 those mathematical expressions the \var{context} is available, but
373 data from other columns are not. Negative numbers count the columns
374 from the end. Example:
375 \begin{verbatim}
376 graph.data.file("test.dat", a=1, b="B", c="2*B+$3")
377 \end{verbatim}
378 with \file{test.dat} looking like:
379 \begin{verbatim}
380 # A B C
381 1.234 1 2
382 5.678 3 4
383 \end{verbatim}
384 The columns with name \samp{a}, \samp{b}, \samp{c} will become
385 \samp{[1.234, 5.678]}, \samp{[1.0, 3.0]}, and \samp{[4.0, 10.0]},
386 respectively.
388 When creating several data instances accessing the same file,
389 the file is read only once. There is an inherent caching of the
390 file contents.
391 \end{classdesc}
393 For the sake of completeness we list the default patterns:
395 \begin{memberdesc}{defaultcommentpattern}
396 \code{re.compile(r\textquotedbl (\#+|!+|\%+)\e s*\textquotedbl)}
397 \end{memberdesc}
399 \begin{memberdesc}{defaultcolumnpattern}
400 \code{re.compile(r\textquotedbl\e \textquotedbl(.*?)\e \textquotedbl(\e s+|\$)\textquotedbl)}
401 \end{memberdesc}
403 \begin{memberdesc}{defaultstringpattern}
404 \code{re.compile(r\textquotedbl(.*?)(\e s+|\$)\textquotedbl)}
405 \end{memberdesc}
407 \begin{classdesc}{function}{expression, title=notitle,
408 min=None, max=None, points=100,
409 parser=mathtree.parser(),
410 context=\{\}}
411 This class creates graph data from a function. \var{expression} is
412 the mathematical expression of the function. It must also contain
413 the result variable name by assignment. Thus a typical example looks
414 like \samp{y=sin(x)}.
416 \var{title} is the title of the data to be used in the graph key. By
417 default \var{expression} is used. You may set \var{title} to
418 \code{None} to disable the title.
420 \var{min} and \var{max} give the range of the variable. If not set,
421 the range spans the whole axis range. The axis range might be set
422 explicitly or implicitly by ranges of other data. \var{points} is
423 the number of points for which the function is calculated. The
424 points are choosen linearly in terms of graph coordinates.
426 \var{parser} is the parser for the mathematical expression. When in
427 doubt, this is probably uninteresting for you. \var{context} allows
428 for accessing external variables and functions. As an example you
429 may use \code{context=locals()} or something similar.
431 Note when accessing external variables: In principle, it is unclear,
432 which of the variables should be used as the
433 dependent variable. The solution is, that there should be exactly
434 one variable, which is a valid and used axis name.
435 Example:
436 \begin{verbatim}
437 [graph.data.function("y=x**i", context=locals()) for i in range(1, 5)]
438 \end{verbatim}
439 The result of this expression could just be passed to a graphs
440 \method{plot()} method, since not only data instances but also lists
441 of data instances are allowed.
442 \end{classdesc}
444 \begin{classdesc}{paramfunction}{varname, min, max, expression,
445 title=notitle, points=100,
446 parser=mathtree.parser(),
447 context=\{\}}
448 This class creates graph data from a parametric function.
449 \var{varname} is the parameter of the function. \var{min} and
450 \var{max} give the range for that variable. \var{points} is the
451 number of points for which the function is calculated. The points
452 are choosen lineary in terms of the parameter.
454 \var{expression} is the mathematical expression for the parametric
455 function. It contains an assignment of a tuple of functions to a
456 tuple of variables.
458 \var{title} is the title of the data to be used in the graph key. By
459 default \var{expression} is used. You may set \var{title} to
460 \code{None} to disable the title.
462 \var{parser} is the parser for mathematical expressions. When in
463 doubt, this is probably uninteresting for you. \var{context} allows
464 for accessing external variables and functions. As an example you
465 may use \code{context=locals()} or something similar.
466 \end{classdesc}
468 \begin{classdesc}{list}{data, title="user provided list",
469 addlinenumbers=1, **columns}
470 This class creates graph data from externally provided data.
471 \var{data} is a list of lines, where each line is a list of data
472 values for the columns.
474 \var{title} is the title of the data to be used in the graph key.
476 The keywords of \var{**columns} become the data column names. The
477 values are the column numbers starting from one, when
478 \var{addlinenumbers} is turned on (the zeroth column is added to
479 contain a line number in that case), while the column numbers starts
480 from zero, when \var{addlinenumbers} is switched off.
481 \end{classdesc}
483 \begin{classdesc}{data}{data, title=notitle, parser=dataparser(),
484 context={}, **columns}
485 This class provides graph data out of other graph data. \var{data}
486 is the source of the data. All other parameters work like the equally
487 called parameters in \class{graph.data.file}. Indeed, the latter is
488 built on top of this class by reading the file and caching its
489 contents in a \class{graph.data.list} instance. The columns are then
490 selected by creating new data out of the existing data.
491 \end{classdesc}
493 \begin{classdesc}{conffile}{filename, title=notitle, parser=dataparser(),
494 context={}, **columns}
495 This class reads data from a config file with the file name
496 \var{filename}. The format of a config file is described within the
497 documentation of the \module{ConfigParser} module of the Python
498 Standard Library.
500 Each section of the config file becomes a data line. The options in
501 a section are the columns. The name of the options will be used as
502 file column names. All other parameters work as in
503 \var{graph.data.file} and \var{graph.data.data} since they all use
504 the same code.
505 \end{classdesc}
507 \section{Module \code{graph/style}: Styles}
508 \label{graph:style}
510 \declaremodule{}{graph.style}
511 \modulesynopsis{Graph style}
513 Please note that we are talking about graph styles here. Those are
514 responsible for plotting symbols, lines, bars and whatever else into a
515 graph. Do not mix it up with path styles like the line width, the line
516 style (solid, dashed, dotted \emph{etc.}) and others.
518 The following classes provide styles to be used at the \method{plot()}
519 method of a graph. The classes are implemented in \module{graph.style}.
521 \begin{classdesc}{symbolline}{symbol=changecross, size="0.2 cm",
522 errorscale=0.5, symbolattrs=[],
523 errorbarattrs=[], lineattrs=[],
524 epsilon=1e-10}
525 This class is a style for plotting symbols, lines and errorbars into a
526 graph. \var{symbol} refers to a (changeable) symbol method (see
527 below). The symbol is drawn at size \var{size} (a visual \PyX{}
528 length; also changeable) using \var{symbolattrs}. \var{symbolattrs}
529 are merged with the decorator \class{deco.stroked}. \var{errorscale}
530 is the size of the error bars compared to the symbol size.
531 \var{errorbarattrs} and \var{lineattrs} are strokestyles for
532 stroking the errorbars and lines, respecively. \var{lineattrs} are
533 merged with \var{changelinestyle} (see below). \var{epsilon} is used
534 to determine, when a symbol is outside of the graph (in graph
535 coordinates).
537 \var{symbolline} is useable on graphs with arbitrary dimension and
538 geometry. It needs one data column for each graph dimension. The
539 data names must be equal to an axis name. Furthermore there can be
540 data names constructed out of the axis names for identifying data
541 for the error bars. Suppose \code{X} is an axis name. Then
542 \class{symbolline} allows for the following data names as well:
544 \begin{tableii}{l|l}{}{data name}{description}
545 \lineii{\code{Xmin}}{minimal value}
546 \lineii{\code{Xmax}}{maximal value}
547 \lineii{\code{dX}}{minimal and maximal delta}
548 \lineii{\code{dXmin}}{minimal delta}
549 \lineii{\code{dXmax}}{maximal delta}
550 \end{tableii}
552 Minimal and maximal values are calculated from delta by subtracting
553 and adding it to the value itself. Most of the data names are mutually
554 exclusive (whenever a minimal or maximal value would be set twice).
555 \end{classdesc}
557 \class{symbolline} provides some symbol methods, namely:
559 \begin{methoddesc}{cross}{x_pt, y_pt, size_pt}
560 A cross. Should be used for stroking only.
561 \end{methoddesc}
563 \begin{methoddesc}{plus}{x_pt, y_pt, size_pt}
564 A plus. Should be used for stroking only.
565 \end{methoddesc}
567 \begin{methoddesc}{square}{x_pt, y_pt, size_pt}
568 A square. Might be stroked or filled or both.
569 \end{methoddesc}
571 \begin{methoddesc}{triangle}{x_pt, y_pt, size_pt}
572 A triangle. Might be stroked or filled or both.
573 \end{methoddesc}
575 \begin{methoddesc}{circle}{x_pt, y_pt, size_pt}
576 A circle. Might be stroked or filled or both.
577 \end{methoddesc}
579 \begin{methoddesc}{diamond}{x_pt, y_pt, size_pt}
580 A diamond. Might be stroked or filled or both.
581 \end{methoddesc}
583 \class{symbolline} provides some changeable symbol methods as class
584 variables, namely:
586 \begin{memberdesc}{changecross}
587 attr.changelist([cross, plus, square, triangle, circle, diamond])
588 \end{memberdesc}
590 \begin{memberdesc}{changeplus}
591 attr.changelist([plus, square, triangle, circle, diamond, cross])
592 \end{memberdesc}
594 \begin{memberdesc}{changesquare}
595 attr.changelist([square, triangle, circle, diamond, cross, plus])
596 \end{memberdesc}
598 \begin{memberdesc}{changetriangle}
599 attr.changelist([triangle, circle, diamond, cross, plus, square])
600 \end{memberdesc}
602 \begin{memberdesc}{changecircle}
603 attr.changelist([circle, diamond, cross, plus, square, triangle])
604 \end{memberdesc}
606 \begin{memberdesc}{changediamond}
607 attr.changelist([diamond, cross, plus, square, triangle, circle])
608 \end{memberdesc}
610 \begin{memberdesc}{changesquaretwice}
611 attr.changelist([square, square, triangle, triangle, circle, circle, diamond, diamond])
612 \end{memberdesc}
614 \begin{memberdesc}{changetriangletwice}
615 attr.changelist([triangle, triangle, circle, circle, diamond, diamond, square, square])
616 \end{memberdesc}
618 \begin{memberdesc}{changecircletwice}
619 attr.changelist([circle, circle, diamond, diamond, square, square, triangle, triangle])
620 \end{memberdesc}
622 \begin{memberdesc}{changediamondtwice}
623 attr.changelist([diamond, diamond, square, square, triangle, triangle, circle, circle])
624 \end{memberdesc}
626 \class{symbolline} provides two changeable decorators for alternated filling
627 and stroking. Those are especially useful in combination with the
628 \method{change}-\method{twice}-symbol methods above. They are:
630 \begin{memberdesc}{changestrokedfilled}
631 attr.changelist([deco.stroked, deco.filled])
632 \end{memberdesc}
634 \begin{memberdesc}{changefilledstroked}
635 attr.changelist([deco.filled, deco.stroked])
636 \end{memberdesc}
638 Finally, there is a changeable line style used by default. It is
639 defined as:
641 \begin{memberdesc}{changelinestyle}
642 attr.changelist([style.linestyle.solid, style.linestyle.dashed, style.linestyle.dotted, style.linestyle.dashdotted])
643 \end{memberdesc}
645 \begin{classdesc}{symbol}{symbol=changecross, size="0.2 cm",
646 errorscale=0.5, symbolattrs=[],
647 errorbarattrs=[], epsilon=1e-10}
648 This class is a style to plot symbols and errorbars into a graph. It
649 is equivalent to \class{symbollines} except that it does not allow
650 for lines. An instance of \class{symbol} is the default style for
651 all data classes described in section~\ref{graph:data} except for
652 \class{function} and \class{paramfunction}.
653 \end{classdesc}
655 \begin{classdesc}{line}{lineattrs=[]}
656 This class is a style to stroke lines into a graph. It is equivalent
657 to \class{symbollines} except that it does not allow for symbols and
658 errorbars. Thus it also does not accept data names for error bars.
659 Instances of \class{line} are the default style for the data classes
660 \class{function} and \class{paramfunction}.
661 \end{classdesc}
663 \begin{classdesc}{text}{textdx="0", textdy="0.3 cm", textattrs=[],
664 symbol=changecross, size="0.2 cm",
665 errorscale=0.5, symbolattrs=[],
666 errorbarattrs=[], epsilon=1e-10}
667 This class enhances \class{symbol} by adding text to the symbol. The
668 text to be written has to be provided in the additional data column named
669 \code{text}. \var{textdx} and \var{textdy} are the position of the
670 text with respect to the symbol. \var{textattrs} are text
671 attributes for the output of the text. All other parameters have the
672 same meaning as in the \class{symbol} class.
673 \end{classdesc}
675 \begin{classdesc}{arrow}{linelength="0.25 cm", arrowsize="0.15 cm",
676 lineattrs=[], arrowattrs=[], epsilon=1e-10}
677 This class is a style to plot short lines with arrows into a
678 two-dimensional graph. The position of the arrow is defined by two
679 data columns named like an axis for each graph dimension. Two
680 additional data columns named \code{size} and \code{angle} define
681 the size and angle for each arrow. \code{size} is taken as a factor
682 to \var{arrowsize} and \var{linelength}, the size of the arrow and
683 the length of the line the arrow is plotted at. \code{angle} is the
684 angle the arrow points to with respect to a horizontal line. The
685 \code{angle} is taken in degrees and used in mathematically positive
686 sense. \var{lineattrs} and \var{arrowattrs} are styles for the arrow
687 line and arrow head, respectively. \var{epsilon} is used to
688 determine, when the arrow is outside of the graph (in graph
689 coordinates).
690 \end{classdesc}
692 \begin{classdesc}{rect}{palette=color.palette.Gray}
693 This class is a style to plot coloured rectangles into a
694 two-dimensional graph. The positions of the rectangles are given by four
695 data columns named \code{Xmin} and \code{Xmax} where \code{X} stands
696 for two axis names, one for each graph dimension. The additional
697 data column named \code{color} specifies the color of the rectangle
698 defined by \var{palette}. Thus the valid color range is [0:1].
700 \begin{note}
701 Although this style can be used for plotting coloured surfaces, it
702 will lead to a huge memory footprint of \PyX{} together with a
703 long running time and large outputs. Improved support for coloured
704 surfaces is planned for the future.
705 \end{note}
706 \end{classdesc}
708 \begin{classdesc}{bar}{fromvalue=None, frompathattrs=[], barattrs=[],
709 subnames=None, epsilon=1e-10}
710 This class is a style to plot bars into a two-dimensional graph. The
711 bars are plotted on top of a specialized axis, namely a bar axis.
712 The data column for this bar axis is named \code{Xname} where
713 \code{X} is an axis name. The bar value has the name of an axis of the
714 other graph dimension. Suppose the name of this value axis is
715 \code{Y} than you can stack further bars on top of this bar by
716 providing additional data columns consecutively named
717 \code{Ystack1}, \code{Ystack2}, \code{Ystack3}, \emph{etc.}
718 When plotting several bars in a single graph, those bars are placed
719 side by side (at the same value of \code{Xname}). The name axis, a
720 bar axis, must then be a nested bar axis. The names used for the
721 subaxis can be set by \var{subnames}. When not set, integer numbers
722 starting from zero will be used.
724 The bars start at \var{fromvalue} when provided. The \var{fromvalue}
725 is marked by a gridline stroked using \var{frompathattrs}. The bars
726 are filled using \var{barattrs}. \var{barattrs} is merged with
727 \samp{[color.palette.Rainbow, deco.stroked([color.gray.black])]} and
728 iterated independently when several bars are plotted side by side
729 and when several bars are plotted on top of each other. When mixing
730 both possibilities, you may use nested changeable styles.
731 \end{classdesc}
733 \section{Module \code{graph/key}: Keys}
734 \label{graph:key}
736 \declaremodule{}{graph.key}
737 \modulesynopsis{Graph keys}
739 The following class provides a key, whose instances can be passed to
740 the constructor keyword argument \code{key} of a graph. The class is
741 implemented in \module{graph.key}.
743 \begin{classdesc}{key}{dist="0.2 cm", pos="tr", hinside=1, vinside=1,
744 hdist="0.6 cm", vdist="0.4 cm",
745 symbolwidth="0.5 cm", symbolheight="0.25 cm",
746 symbolspace="0.2 cm", textattrs=[]}
747 This class writes the title of the data in a plot together with a
748 small illustration of the style. The style is responsible for its
749 illustration.
751 \var{dist} is a visual length and a distance between the key
752 entries. \var{pos} is the position of the key with respect to the
753 graph. Allowed values are combinations of \samp{t} (top) and
754 \samp{b} (bottom) with \samp{l} (left) and \samp{r} (right).
755 \var{hdist} and \var{vdist} are the distances from the specified
756 corner of the graph. \var{hinside} and \var{vinside} are booleans to
757 define whether the key should be placed horizontally and vertically
758 inside of the graph or not.
760 \var{symbolwidth} and \var{symbolheight} are passed to the style to
761 control the size of the style illustration. \var{symbolspace} is the
762 space between the illustration and the text. \var{textattrs} are
763 attributes for the text creation. They are merged with
764 \samp{[text.vshift.mathaxis]}.
765 \end{classdesc}