chmod
[PyX/mjg.git] / manual / graph.tex
blob71dec1e15e94d84c4d32218a02635c2eef44cfe3
1 \chapter{Module graph: graph plotting}
2 \label{graph}
3 \section{Introductory notes}
5 The graph module is considered to be in constant, gradual development.
6 For the moment we concentrate ourself on standard 2d xy-graphs taking
7 all kind of possible specialties into account like any number of axes.
8 Architectural decisions play the most substantial role at the moment
9 and have hopefully already been done that way, that their flexibility
10 will suffice for future usage in quite different graph applications,
11 \emph{e.g.} circular 2d graphs or even 3d graphs. We will describe
12 those parts of the graph module here, which are in a totally usable
13 state already and are hopefully not to be changed later on. However,
14 future developments certainly will cause some incompatibilities. At
15 least be warned: Nobody knows the hole list of things that will break.
16 At the moment, keeping backwards compatibility in the graph module is
17 not at all an issue. Although we do not yet claim any backwards
18 compatibility for the future at all, the graph module is certainly one
19 of the biggest construction sites within \PyX.
21 The task of drawing graphs is splitted in quite some subtasks, which
22 are implemented by classes of its own. We tried to make those
23 components as independend as it is usefull and possible in order to
24 make them reuseable for different graph types. They are also
25 replaceable by the user to get more specialized graph drawing tasks
26 done without needing to implement a hole graph system. A major
27 abstraction layer are the so-called graph coordinates. Their range is
28 generally fixed to $[0;1]$. Only the graph does know about the
29 conversion between these coordinates and the position at the canvas.
30 By that, all other components can be reused for different graph
31 geometries.
33 \section{Axes}
34 \label{graph:axes}
36 A common feature of a graph are axes. An axis is responsible for the
37 conversion of values to graph coordinates. There are predefined axis
38 types, namely:
39 \begin{center}
40 \begin{tabular}{ll}
41 axis type&description\\
42 \hline
43 \texttt{linaxis}&linear axis\\
44 \texttt{logaxis}&logarithmic axis\\
45 \end{tabular}
46 \end{center}
48 Further axes types are available to support axes splitting and bar
49 graphs (other axes types might be added in the future as well), but
50 they behave quite different from the generic case and are thus
51 described separately below.
53 \subsection{Axes properties}
55 Global properties of an axis are set as named parameters in the axis
56 constructor. Both, the \verb|linaxis| and the \verb|logaxis|, have the
57 same set of named parameters listed in the following table:
59 \medskip
60 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
61 argument name&description\\
62 \hline
63 \texttt{title}&axis title\\
64 \texttt{min}&fixes axis minimum; if not set, it is automatically determined, but this might fail, for example for the $x$-range of functions, when it is not specified there\\
65 \texttt{max}&as above, but for the maximum\\
66 \texttt{reverse}&boolean; exchange minimum and maximum (might be used without setting minimum and maximum); if min>max and reverse is set, they cancel each other\\
67 \texttt{divisor}&numerical divisor for the axis partitioning; default: \texttt{1}\\
68 \texttt{suffix}&a suffix to indicate the divisor within an automatic axis labeling\\
69 \texttt{datavmin}&minimal graph coordinate when adjusting the axis minima to the graph data; default: \texttt{0.05} (or \texttt{0}, when min is present)\\
70 \texttt{datavmax}&as above, but for the maximum; default: \texttt{0.95} (or \texttt{1}, when max is present)\\
71 \texttt{tickvmin}&minimal graph coordinate for placing ticks to the axis; default: \texttt{0}\\
72 \texttt{tickvmax}&as above, but for the maximum; default: \texttt{1}\\
73 \texttt{part}&axis partitioning (described below)\\
74 \texttt{rate}&axis partition rating (described below)\\
75 \texttt{dense}&dense parameter for the axis partition rating; if not set, the dense value for the graph is used\\
76 \texttt{painter}&axis painter (described below)\\
77 \end{tabularx}
78 \medskip
80 \subsection{Partitioning of axes}
82 The definition of ticks and labels appropriate to an axis range is
83 called partitioning. The axis partioning within \PyX{} uses rational
84 arithmetics, which avoids any kind of rounding problems to the cost of
85 performance. The class \verb|frac| supplies a rational number.
86 However, a partitioning is composed out of a sorted list of ticks,
87 where the class \verb|tick| is derived from \verb|frac| and has
88 additional properties called \verb|ticklevel| and \verb|labellevel|.
89 When those values are \verb|None|, it just means not present, \verb|0|
90 means tick or label, respectively, \verb|1| means subtick or sublevel
91 and so on. When \verb|labellevel| is not \verb|None|, a \verb|text|
92 might be explicitly given, which will get used as the text of that
93 label. Otherwise the axis painter has to create an appropriate text
94 for the label.
96 We will first discuss manual partitioning schemes, namely a plain
97 manual partition, another appropriate for linear axes and a third one
98 for logarithmic axes. These partition schemes might be used directly
99 or indirectly via automatic axis partioning schemes.
101 \subsubsection{Manual partitioning}
103 The class \verb|manualpart| creates a manual partition where every
104 single tick, label etc. is set independendly from each other as
105 described by named parameters of the constructor:
107 \medskip
108 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
109 argument name&default&description\\
110 \hline
111 \texttt{ticks}&\texttt{None}&position of ticks, subticks, etc. (see below)\\
112 \texttt{labels}&\texttt{None}&position of labels, sublabels, etc. (see below)\\
113 \texttt{texts}&\texttt{None}&force text at labels, sublabels, etc. (see below)\\
114 \texttt{mix}&\texttt{()}&ordered tick list to be merged into the result\\
115 \end{tabularx}
116 \medskip
118 The parameters \verb|ticks|, \verb|labels|, and \verb|texts| can
119 either be a sequence, or a sequence of sequences. (When it is not a
120 sequence at all, it is converted to a sequence with a single entry.)
121 When it is a sequence of sequences, than the first sequence stands for
122 the ticks, labels, and texts of the labels, the second sequence stands
123 for the subticks, sublabels, and texts of the sublabels, and so on.
124 When it is just a sequence, it stands for the ticks, labels and texts
125 of the labels and no subticks, sublabels and subtexts will be created.
127 The single entries of \verb|ticks| and \verb|labels| can either be a
128 frac or a string, which will be converted to a frac. However, a float
129 is not valid in order to avoid a conversion from a float to a frac.
130 Valid strings are just numbers like \verb|"0.1"|, or fractions like
131 \verb|"1/10"|.
133 \subsubsection{Partitioning of linear axes}
135 The class \verb|linpart| creates a linear partition as described by
136 named parameters of the constructor:
138 \medskip
139 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
140 argument name&default&description\\
141 \hline
142 \texttt{ticks}&\texttt{None}&distance between ticks, subticks, etc. (see comment below); when the parameter is \texttt{None}, ticks will get placed at labels\\
143 \texttt{labels}&\texttt{None}&distance between labels, sublabels, etc. (see comment below); when the parameter is \texttt{None}, labels will get placed at ticks\\
144 \texttt{extendtick}&\texttt{0}&allow for a range extention to include the next tick of the given level\\
145 \texttt{extendlabel}&\texttt{None}&as above, but for labels\\
146 \texttt{epsilon}&\texttt{1e-10}&allow for exceeding the range by that relative value\\
147 \texttt{texts}&\texttt{None}&as in manualpart\\
148 \texttt{mix}&\texttt{()}&as in manualpart\\
149 \end{tabularx}
150 \medskip
152 The \verb|ticks| and \verb|labels| can either be a sequence or just a
153 single entry. When a sequence is provided, the first entry stands for
154 the tick or label, respectively, the second for the subtick or
155 sublabel, and so on. The entries can either be a frac or a string,
156 as in \verb|manualpart|.
158 \subsubsection{Partitioning of logarithmic axes}
160 The class \verb|logpart| create a logarithmic partition. The class has
161 the same arguments as \verb|linpart| upto the interpretation of two
162 arguments \verb|ticks| and \verb|labels|. Both parameters can contain
163 just a single entry or a sequence --- the interpretation of those
164 possibilities is the same as it was for \verb|linpart|. The entries
165 have to be \verb|shiftfracs|, which contains a \verb|frac| for the
166 shift, say $s$, and a list of \verb|frac| for the positions, say
167 $p_i$. Valid positions are then $s^np_i$, where $n$ can be any integer
168 number. Within \verb|logpart| there are numerous predefined
169 \verb|shiftfracs|, namely:
171 \begin{center}
172 \begin{tabular}{ll}
173 name&values it descibes\\
174 \hline
175 \texttt{shift5fracs1}&1 and multiple of $10^5$\\
176 \texttt{shift4fracs1}&1 and multiple of $10^4$\\
177 \texttt{shift3fracs1}&1 and multiple of $10^3$\\
178 \texttt{shift2fracs1}&1 and multiple of $10^2$\\
179 \texttt{shiftfracs1}&1 and multiple of $10$\\
180 \texttt{shiftfracs125}&1, 2, 5 and multiple of $10$\\
181 \texttt{shiftfracs1to9}&1, 2, \dots, 9 and multiple of $10$\\
182 \end{tabular}
183 \end{center}
185 \subsubsection{Automatic partitioning of linear axes}
187 When no explicit axis partitioning is given in the constructor of an
188 linear axis, it is initialized with an automatic partitioning schemes
189 for linear axes. This scheme is provided by the class
190 \verb|autolinpart|, where the constructor takes the following
191 arguments:
193 \medskip
194 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
195 argument name&default&description\\
196 \hline
197 \texttt{list}&\texttt{defaultlist}&list of possible values for the ticks parameter of \texttt{linpart} (labels are placed at the position of ticks)\\
198 \texttt{extendtick}&\texttt{0}&allow for a range extention to include the next tick of the given level\\
199 \texttt{epsilon}&\texttt{1e-10}&allow for exceeding the range by that relative value\\
200 \texttt{mix}&\texttt{()}&as in manualpart\\
201 \end{tabularx}
202 \medskip
204 The default value for the argument \verb|list|, namely
205 \verb|defaultlist|, is defined as a class variable of
206 \verb|autolinpart| and has the value \texttt{((frac(1, 1), frac(1,
207 2)), (frac(2, 1), frac(1, 1)), (frac(5, 2), frac(5, 4)), (frac(5, 1),
208 frac(5, 2)))}. This implies, that the automatic axis partitioning
209 scheme allows for partitions using (ticks, subticks) with at distances
210 (1, 1/2), (2, 1), (5/2, 5/4), (5, 5/2). This list must be sorted by
211 the number of ticks the entries will lead to. Additionally, as most
212 likely already from the default value of the argument \verb|list|, the
213 given fractions are automatically multiplied or divided by 10 in order
214 to fit better to the axis range. Therefore these additional
215 partitioning possibilities must not be given explicitly.
217 \subsubsection{Automatic partitioning of logarithmic axes}
219 When no explicit axis partitioning is given in the constructor of an
220 logarithmic axis, it is initialized with an automatic partitioning
221 schemes for logarithmic axes. This scheme is provided by the class
222 \verb|autologpart|, where the constructor takes the following
223 arguments:
225 \medskip
226 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
227 argument name&default&description\\
228 \hline
229 \texttt{list}&\texttt{defaultlist}&list of pairs with possible values for the ticks and labels parameters of \texttt{logpart}\\
230 \texttt{extendtick}&\texttt{0}&allow for a range extention to include the next tick of the given level\\
231 \texttt{extendlabel}&\texttt{None}&as above, but for labels\\
232 \texttt{epsilon}&\texttt{1e-10}&allow for exceeding the range by that relative value\\
233 \texttt{mix}&\texttt{()}&as in manualpart\\
234 \end{tabularx}
235 \medskip
237 The default value for the argument \verb|list|, namely
238 \verb|defaultlist|, is defined as a class variable of
239 \verb|autologpart| and has the value:
240 \begin{verbatim}
241 (((shiftfracs1, shiftfracs1to9), # ticks & subticks,
242 (shiftfracs1, shiftfracs125)), # labels & sublevels
243 ((shiftfracs1, shiftfracs1to9), None), # ticks & subticks, labels=ticks
244 ((shift2fracs1, shiftfracs1), None), # ticks & subticks, labels=ticks
245 ((shift3fracs1, shiftfracs1), None), # ticks & subticks, labels=ticks
246 ((shift4fracs1, shiftfracs1), None), # ticks & subticks, labels=ticks
247 ((shift5fracs1, shiftfracs1), None)) # ticks & subticks, labels=ticks
248 \end{verbatim}
249 As for the \verb|autolinaxis|, this list must be sorted by the number
250 of ticks the entries will lead to.
252 \subsubsection{Rating of axes partitionings}
254 When an axis partitioning scheme returns several partitioning
255 possibilities, the partitions are rated by an instance of a rater
256 class provided as the parameter \verb|rate| at the axis constructor.
257 It is used to calculate a positive rating number for a given axis
258 partitioning. In the end, the lowest rated axis partitioning gets
259 used.
261 The rating consists of two steps. The first takes into account only
262 the number of ticks, subticks, labels and so on in comparison to an
263 optimal number. Additionally, the transgression of the axis range by
264 ticks and labels is taken into account. This rating leads to a
265 preselection of possible partitions. In the second step the layout of
266 a partition gets acknowledged by rating the distance of the labels to
267 each other. Thereby partitions with overlapping labels get quashed
268 out.
270 The class \verb|axisrater| implements a rating with quite some
271 parameters specifically adjusted to linear and logarithmic axes. A
272 detailed description of the hole system goes beyond the scope of that
273 manual. Take your freedom and have a look at the \PyX{} source code if
274 you wish to adopt the rating to personal preferences.
276 The overall optimal partition properties, namely the density of ticks
277 and labels, can be easily adjusted by the single parameter
278 \verb|dense| of the axis (or graph) constructor. The rating is
279 adjusted to the default densitiy value of \verb|1|, but modifications
280 of this parameter in the range of 0.5 (for less ticks) to 2 or even 3
281 (for more ticks) might be usefull. This parameter was taken out of the
282 rating class for easier access.
284 \subsection{Painting of axes}
286 A major task for an axis is its painting. It is done by instances of
287 \verb|axispainter|, provided to the constructor of an axis as its
288 \verb|painter| argument. The constructor of the axis painter receives
289 a numerous list of named parameters to modify the axis look. A list of
290 parameters is provided in the following table:
292 \medskip
293 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
294 argument name&description\\
295 \hline
296 \texttt{innerticklengths}$^{1,4}$&tick length of inner ticks (visual length);\newline default: \texttt{axispainter.defaultticklengths}\\
297 \texttt{outerticklengths}$^{1,4}$&as before, but for outer ticks; default: \texttt{None}\\
298 \texttt{tickattrs}$^{2,4}$&stroke attributes for ticks; default: \texttt{()}\\
299 \texttt{gridattrs}$^{2,4}$&stroke attributes for grid lines; default: \texttt{None}\\
300 \texttt{zerolineattrs}$^{3,4}$&stroke attributes for a grid line at axis value 0; default: \texttt{()}\\
301 \texttt{baselineattrs}$^{3,4}$&stroke attributes for the axis baseline;\newline default: \texttt{canvas.linecap.square}\\
302 \texttt{labeldist}&label distance from axis (visual length); default: \texttt{"0.3 cm"}\\
303 \texttt{labelattrs}$^{2,4}$&text attributes for labels;\newline default: \texttt{((textmodule.halign.center, textmodule.vshift.mathaxis), (textmodule.size.footnotesize, textmodule.halign.center, textmodule.vshift.mathaxis))}\\
304 \texttt{labeldirection}$^4$&relative label direction (see below); default: \texttt{None}\\
305 \texttt{labelhequalize}&set width of labels to its maximum (boolean); default: \texttt{0}\\
306 \texttt{labelvequalize}&set height and depth of labels to their maxima (boolean); default: \texttt{1}\\
307 \texttt{titledist}&title distance from labels (visual length); default: \texttt{"0.3 cm"}\\
308 \texttt{titleattrs}$^{3,4}$&text attributes for title; default: \texttt{()}\\
309 \texttt{titledirection}$^4$&relative title direction (see below);\newline default: \texttt{axispainter.paralleltext}\\
310 \texttt{titlepos}&title position in graph coordinates; default: \texttt{0.5}\\
311 \texttt{fractype}&text creation for labels (see below);\newline default: \texttt{axispainter.fractypeauto}\\
312 \texttt{ratfracsuffixenum}&write suffix at the enumerator (boolean); default: \texttt{1}\\
313 \texttt{ratfracover}&text for fraction line; default: \texttt{r"\textbackslash over"}\\
314 \texttt{decfracpoint}&decimal point; default: \texttt{"."}\\
315 \texttt{decfracequal}&equalize number of decimal digits (boolean); default: \texttt{0}\\
316 \texttt{expfractimes}&text between factor and decimal power; default: \texttt{r"\textbackslash cdot"}\\
317 \texttt{expfracpre1}&allow factor 1 before a decimal power (boolean); default: \texttt{0}\\
318 \texttt{expfracminexp}&minimal exponent for decimal power; default: \texttt{4}\\
319 \texttt{suffix0}&when a suffix is \texttt{x} write \texttt{0x} instead of \texttt{0} (boolean); default: \texttt{0}\\
320 \texttt{suffix1}&when a suffix is \texttt{x} write \texttt{1x} instead of \texttt{x} (boolean); default: \texttt{0}\\
321 \end{tabularx}
322 \medskip
324 $^1$
325 The parameter should be a sequence, where the entries are attributes
326 for the different levels. When the level is larger then the sequence
327 length, \verb|None| is assumed. When the parameter is not a sequence,
328 it is applied to all levels.\\
329 $^2$
330 The parameter should be a sequence of sequences, where the entries are
331 attributes for the different levels. When the level is larger then the
332 sequence length, \verb|None| is assumed. When the parameter is not a
333 sequence of sequences, it is applied to all levels.\\
334 $^3$
335 The parameter should be a sequence. When the parameter is not a
336 sequence, the parameter is interpreted as a sequence with a single
337 entry.\\
338 $^4$
339 The feature can be turned off by the value \verb|None|. Within
340 sequences or sequences of sequences, the value \verb|None| might be
341 used to turn off the feature for some levels selectively.
342 \medskip
344 Relative directions for labels (\verb|labeldirection|) and titles
345 (\verb|titledirection|) are basically a float number in degree. The
346 text direction is calculated relatively to the baseline of the axis
347 and is added as an attribute of the text, when no direction was
348 already provided. The relative direction prevents upside down text by
349 flipping it by 180 degrees. For convenience, the two self-explanatory
350 values \verb|axispainter.paralleltext| and
351 \verb|axispainter.orthogonaltext| are available.
353 The \verb|fractype| parameter determines the creation of label texts.
354 There are three types available, which can be forced by providing them
355 to the \verb|fractype| parameter. The possibilities are listed in the
356 following table.
358 \begin{center}
359 \begin{tabular}{lll}
360 \texttt{fractype}&description&example\\
361 \hline
362 \texttt{axispainter.fractypedec}&decimal&$0.1$\\
363 \texttt{axispainter.fractypeexp}&decimal with exponent&$2\cdot 10^4$\\
364 \texttt{axispainter.fractyperat}&rational&$\displaystyle{{1}\over{2}}$\\
365 \texttt{axispainter.fractypeauto}&automatic (see below)&\\
366 \end{tabular}
367 \end{center}
369 For the default \verb|axispainter.fractypeauto| the three
370 possibilities are selected depending on some simple rules:
371 \verb|axispainter.fractyperat| is used, when the axis provides a
372 suffix, \verb|axispainter.fractypeexp| is used, when the exponent
373 exceed \verb|expfracminexp|, and \verb|axispainter.fractypedec| is
374 used otherwise.
376 \subsection{Linked axes}
378 Linked axes can be used whenever an axis should be repeated within a
379 single graph or even between different graphs although the intrinsic
380 meaning is to have only one axis plotted several times. The
381 constructor of \verb|linkaxis| receives the axis it is linked to as
382 its first parameter. Additionally, the named parameter \verb|title|
383 contains an axis title (default is \verb|None|) and the named
384 parameter \verb|painter| refers to an axispainter (default is
385 \verb|linkaxispainter|). This \verb|linkedaxispainter| is a slightly
386 modified version of the standard \verb|axispainter|. Hence it can
387 receive all the parameters as the \verb|axispainter| and only the
388 default value of the parameter \verb|zerolineattrs| is changed to
389 \verb|None| compared to the \verb|axispainter| previously discussed.
390 Additionally, two parameters are added, namely \verb|skipticklevel|
391 and \verb|skiplabellevel|. They are used to build the tick list to be
392 plotted at the linked axis. Ticks and labels at levels equal or higher
393 as the provided values get ignored. The default is \verb|None| (do not
394 ignore any ticks) for the ticks and \verb|0| (ignore all labels) for
395 the labels.
397 \subsection{Special purpose axes}
399 \subsubsection{Splitable axes}
401 Axes with breaks are created by instances of the class
402 \verb|splitaxis|. Its constructor takes the following parameters:
404 \medskip
405 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
406 argument name&description\\
407 \hline
408 (axis list)&a list of axes to be used as subaxes (this is the first parameter of the constructor; it has no name)\\
409 \texttt{splitlist}&a single number or a list split points of the possitions of the axis breaks in graph coordinates; the value \texttt{None} forces \texttt{relsizesplitdist} to be used; default: \texttt{0.5}\\
410 \texttt{splitdist}&gap of the axis break; default: \texttt{0.1}\\
411 \texttt{relsizesplitdist}&used when \texttt{splitlist} entries are \texttt{None}; gap of the axis break in values of the surrounding axes (on logarithmic axes, a decade corresponds to 1); the split position is adjusted to give both surrounding axes the same scale (thus, their range must be completely fixed); default: \texttt{1}\\
412 \texttt{title}&axis title\\
413 \texttt{painter}&axis painter; default: \texttt{splitaxispainter()} (described below)\\
414 \end{tabularx}
415 \medskip
417 A split axis is build up from a list of ``subaxes''. Those subaxes
418 have to provide some range information needed to identify the subaxis
419 to be used out of a plain number (thus all axes minima and maxima has
420 to be set except for the two subaxes at the egde, where for the first
421 only the maximum is needed, while for the last only the minimum is
422 needed). The only point left is the description of the specialized
423 \verb|splitaxispainter|, where the constructor takes the following
424 parameters:
426 \medskip
427 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
428 argument name&description\\
429 \hline
430 \texttt{breaklinesdist}&(visual) distance between the break lines; default: \texttt{0.05}\\
431 \texttt{breaklineslength}&(visual) length of break lines; default: \texttt{0.5}\\
432 \texttt{breaklinesangle}&angle of the breakline with respect to the axis; default: \texttt{-60}\\
433 \texttt{breaklinesattrs}&stroke attributes for the break lines (\texttt{None} to turn off the break lines, otherwise a single value or a tuple); default: \texttt{()}\\
434 \end{tabularx}
436 Additionally, the painter takes parameters for the axis title
437 formatting like the standard axis painter class \verb|axispainter|.
438 The parameters are \verb|titledist|, \verb|titleattrs|,
439 \verb|titledirection|, and \verb|titlepos|.
441 \subsubsection{Bar axes}
443 Axes appropriate for bar graphs are created by instances of the class
444 \verb|baraxis|. Its constructor takes the following parameters:
446 \medskip
447 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
448 argument name&description\\
449 \hline
450 \texttt{subaxis}&baraxis can be recursive by having another axis as its subaxis; default: \texttt{None}\\
451 \texttt{multisubaxis}&allow for multiple subaxis (boolean); default: \texttt{0}\\
452 \texttt{title}&axis title\\
453 \texttt{dist}&distance between bars (relative to the bar width); default: \texttt{0.5}\\
454 \texttt{firstdist}&distance of the first bar to the border; default: \texttt{0.5*dist}\\
455 \texttt{lastdist}&as before but for the last bar\\
456 \texttt{names}&tuple of name identifiers for bars; when set, no other identifiers are allowed; default: \texttt{None}\\
457 \texttt{texts}&dictionary translating names into label texts (otherwise just the names are used); default: \texttt{\{\}}\\
458 \texttt{painter}&axis painter; default: \texttt{baraxispainter} (described below)\\
459 \end{tabularx}
460 \medskip
462 In contrast to other axes, a bar axis uses name identifiers to
463 calculate a possition at the axis. Usually, a style appropriate to a
464 bar axis (this is right now just the bar style) set those names out of
465 the data it recieves. However, the names can be forced and fixed.
467 Bar axes can be recursive. Thus for a given value, an appropriate
468 subaxis is choosen (usually another bar axis). Usually only a single
469 subaxis is needed, because for each value the same recursive subaxis
470 transformation has to be applied. However, this prevents the subaxis
471 to be painted, but as soon as multisubaxis is turned on, the subaxes
472 (note axes instead of axis) are painted as well (however their painter
473 can be set to not paint anything). For that, duplications of the
474 subaxis are created for each name (right now, this is only available
475 for the bar axis). By that, each subaxis can have different names, in
476 particular different number of names.
478 The only point left is the description of the specialized
479 \verb|baraxispainter|. It works quite similar to the
480 \verb|axispainter|. Thus the constructors have quite some parameters
481 in common, namely \verb|titledist|, \verb|titleattrs|,
482 \verb|titledirection|, \verb|titlepos|, and \verb|baselineattrs|.
483 Furthermore the parameters \verb|innerticklength| and
484 \verb|outerticklength| work like their counterparts in the
485 \verb|axispainter|, but only plain values are allowed there (no
486 tuples). However, they are both \verb|None| by default and no ticks
487 get plotted. Then there is a hole bunch of name
488 attribute identifiers, namely \verb|namedist|, \verb|nameattrs|,
489 \verb|namedirection|, \verb|namehequalize|, \verb|namevequalize| which
490 are identical to their counterparts called \verb|label...| instead of
491 \verb|name...|. Last but not least, there is a parameter \verb|namepos|
492 which is analogous to \verb|titlepos| and set to \verb|0.5| by
493 default.
495 \section{Data}
496 \label{graph:data}
498 \subsection{List of points}
500 Instances of the class \verb|data| link together a \verb|datafile| (or
501 another instance of a class from the module \verb|data|) and a
502 \verb|style| (see below; default is \verb|symbol|). The link object is
503 needed in order to be able to plot several data from a singe file
504 without reading the file several times. However, for easy usage, it is
505 possible to provide just a filename instead of a \verb|datafile|
506 instance as the first argument to the constructor of the class
507 \verb|data| thus hiding the underlying \verb|datafile| instance
508 completely from view. This is the preferable solution as long as the
509 datafile gets used only once.
511 The additional parameters of the constructor of the class \verb|data|
512 are named parameters. The values of those parameters describe data
513 columns which are linked to the names of the parameters within the
514 style. The data columns can be identified directly via their number or
515 title, or by means of mathematical expression (as in the addcolumn
516 method of the class \verb|data| in the module \verb|data|; see
517 chapter~\ref{module:data}; indeed a addcolumn call takes place to
518 evaluate mathematical expressions once and for all).
520 The constructors keyword argument \verb|title| however does not
521 refer to a parameter of a style, but instead sets the title to be used
522 in an axis key.
524 \subsection{Functions}
526 The class \verb|function| provides data generation out of a functional
527 expression. The default style for function plotting is \verb|line|.
528 The constructor of \verb|function| takes an expression as the first
529 parameter. The expression must be a string with exactly one equal sign
530 (\verb|=|). At the left side the result axis identifier must be placed
531 and at the right side the expression must depend on exactly one
532 variable axis identifier. Hence, a valid expression looks like
533 \verb|"y=sin(x)"|. You can access own variables and functions by
534 providing them as a dictionary to the constructors \verb|context|
535 keyword argument.
537 Additional named parameters of the constructor are:
539 \medskip
540 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
541 argument name&default&description\\
542 \hline
543 \texttt{min}&\texttt{None}&minimal value for the variable parameter; when \texttt{None}, the axis data range will be used\\
544 \texttt{max}&\texttt{None}&as above, but for the maximum\\
545 \texttt{points}&\texttt{100}&number of points to be calculated\\
546 \texttt{parser}&\texttt{mathtree.parser()}&parser for the mathematical expression\\
547 \texttt{context}&\texttt{None}&dictionary of extern variables and functions\\
548 \texttt{title}&equal to the expression&title to be used in the graph key\\
549 \end{tabularx}
550 \medskip
552 The expression evaluation takes place at a linear raster on the
553 variable axis. More advanced methods (detection of rapidely changing
554 functions, handling of divergencies) are likely to be added in future
555 releases.
557 \subsection{Parametric functions}
559 The class \verb|paramfunction| provides data generation out of a
560 parametric representation of a function. The default style for
561 parametric function plotting is \verb|line|. The parameter list of the
562 constructor of \verb|paramfunction| starts with three parameters
563 describing the function parameter. The first parameter is a string,
564 namely the variable name. It is followed by a minimal and maximal
565 value to be used for that parameter. The next parameter contains an
566 expression assigning functions to the axis identifiers in a quite
567 pythonic tuple notation. As an example, such an expression could look
568 like \verb|"x, y = sin(k), cos(3*k)"|.
570 Additionally, the named parameters \verb|points|, \verb|parser|,
571 \verb|context|, and \verb|title| behave like their equally named
572 counterparts in \verb|function|.
574 \section{Styles}
575 \label{graph:styles}
577 Styles are used to draw data at a graph. A style determines what is
578 painted and how it is painted. Due to this powerfull approach there
579 are already some different styles available and the possibility to
580 introduce other styles opens even more prospects.
582 \subsection{Symbols}
584 The class \verb|symbol| can be used to plot symbols, errorbars and lines
585 configurable by parameters of the constructor. Providing \verb|None|
586 to attributes hides the according component.
588 \medskip
589 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
590 argument name&default&description\\
591 \hline
592 \texttt{symbol}&\texttt{changesymbol.cross()}&symbol to be used (see below)\\
593 \texttt{size}&\texttt{"0.2 cm"}&size of the symbol (visual length)\\
594 \texttt{symbolattrs}&\texttt{canvas.stroked()}&draw attributes for the symbol\\
595 \texttt{errorscale}&\texttt{0.5}&size of the errorbar caps (relative to the symbol size)\\
596 \texttt{errorbarattrs}&\texttt{()}&stroke attributes for the errorbars\\
597 \texttt{lineattrs}&\texttt{None}&stroke attributes for the line\\
598 \end{tabularx}
599 \medskip
601 The parameter \verb|symbol| has to be a routine, which returns a path to
602 be drawn (e.g. stroked or filled). There are several such routines
603 already available in the class \verb|symbol|, namely \verb|cross|,
604 \verb|plus|, \verb|square|, \verb|triangle|, \verb|circle|, and
605 \verb|diamond|. Furthermore, changeable attributes might be used here
606 (like the default value \verb|changesymbol.cross|), see
607 section~\ref{graph:changeattrs} for details.
609 The attributes are available as class variables after plotting the
610 style for outside usage. Additionally, the variable \verb|path|
611 contains the path of the line (even when it wasn't plotted), which
612 might be used to get crossing points, fill areas, etc.
614 Valid data names to be used when providing data to symbols are listed
615 in the following table. The character \verb|X| stands for axis names
616 like \verb|x|, \verb|x2|, \verb|y|, etc.
618 \begin{center}
619 \begin{tabular}{ll}
620 data name&description\\
621 \hline
622 \texttt{X}&position of the symbol\\
623 \texttt{Xmin}&minimum for the errorbar\\
624 \texttt{Xmax}&maximum for the errorbar\\
625 \texttt{dX}&relative size of the errorbar: \texttt{Xmin, Xmax = X-dX, X+Xd}\\
626 \texttt{dXmin}&relative minimum \texttt{Xmin = X-dXmin}\\
627 \texttt{dXmax}&relative maximum \texttt{Xmax = X+dXmax}\\
628 \end{tabular}
629 \end{center}
631 \subsection{Lines}
633 The class \verb|line| is inherited from the class \verb|symbol| and
634 restricted itself to line drawing. The constructor takes only the
635 \verb|lineattrs| keyword argment, which is by default set to
636 \verb|(changelinestyle(), canvas.linejoin.round)|. The other features
637 of the symbol style are turned off.
639 \subsection{Rectangles}
641 The class \verb|rect| draws filled rectangles into a graph. The size
642 and the position of the rectangles to be plotted can be provided by
643 the same data names like for the errorbars of the class \verb|symbol|.
644 Indeed, the class \verb|symbol| reuses most of the symbol code by
645 inheritance, while modifying the errorbar look into a colored filled
646 rectangle and turing off the symbol itself.
648 The color to be used for the filling of the rectangles is taken from a
649 palette provided to the constructor by the named parameter
650 \verb|palette| (default is \verb|color.palette.Gray|). The data
651 name \verb|color| is used to select the color out of this palette.
653 \subsection{Texts}
655 Another style to be used within graphs is the class \verb|text|, which
656 adds the output of text to the class \verb|symbol|. The text
657 position relative to the symbol is defined by the two named
658 parameters \verb|textdx| and \verb|textdy| having a default of
659 \verb|"0 cm"| and \verb|"0.3 cm"|, respectively, which are by default
660 interpreted as visual length. A further named parameter
661 \verb|textattrs| may contain a sequence of text attributes (or just a
662 single attribute). The default for this parameter is
663 \verb|text.halign.center|. Furthermore the constructor of this class
664 allows all other attributes of the class \verb|symbol|.
666 \subsection{Arrows}
668 The class \verb|arrow| can be used to plot small arrows into a graph
669 where the size and direction of the arrows has to be given within the
670 data. The constructor of the class takes the following parameters:
672 \medskip
673 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
674 argument name&default&description\\
675 \hline
676 \texttt{linelength}&\texttt{"0.2 cm"}&length of a the arrow line (visual length)\\
677 \texttt{arrowattrs}&\texttt{()}&stroke attributes\\
678 \texttt{arrowsize}&\texttt{"0.1 cm"}&size of the arrow (visual length)\\
679 \texttt{arrowdict}&\texttt{\{\}}&attributes to be used in the \texttt{earrow} constructor\\
680 \texttt{epsilon}&1e-10&smallest allowed arrow size factor for a arrow to become plotted (avoid numerical instabilities)\\
681 \end{tabularx}
682 \medskip
684 The arrow allows for data names like the symbol and introduces
685 additionally the data names \verb|size| for the arrow size (as an
686 multiplicator for the sizes provided to the constructor) and
687 \verb|angle| for the arrow direction (in degree).
689 \subsection{Bars}
691 The class \verb|bar| must be used in combination with an
692 \verb|baraxis| in order to create bar plots. The constructor takes the
693 following parameters:
695 \medskip
696 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
697 argument name&description\\
698 \hline
699 \texttt{fromzero}&bars start at zero (boolean); default: \texttt{1}\\
700 \texttt{stacked}&stack bars (boolean/integer); for values bigger than 1 it is the number of bars to be stacked; default: \texttt{0}\\
701 \texttt{skipmissing}&skip entries in the bar axis, when datapoints are missing; default: \texttt{1}\\
702 \texttt{xbar}&bars parallel to the graphs x-direction (boolean); default: \texttt{0}\\
703 \texttt{barattrs}&fill attributes; default: \texttt{(canvas.stroked(color.gray.black), changecolor.Rainbow())}\\
704 \end{tabularx}
706 Additionally, the bar style takes two data names appropriate to the
707 graph (like \verb|x|, \verb|x2|, and \verb|y|).
709 \subsection{Iterateable style attributes}
710 \label{graph:changeattrs}
712 The attributes provided to the constructors of styles can usually
713 handle so called iterateable attributes, which are changing itself
714 when plotting several data sets. Iterateable attributes can be easily
715 written, but there are already some iterateable attributes available
716 for the most common cases. For example a color change is done by
717 instances of the class \verb|colorchange|, where the constructor takes
718 a palette. Applying this attribute to a style and using this style at
719 a sequence of data, the color will get changed lineary along the
720 palette from one end to the other. The class \verb|colorchange|
721 includes inherited classes as class variables, which are called like
722 the color palettes shown in appendix~\ref{palettename}. For them the
723 default palette is set to the appropriate color palette.
725 Another attribute changer is called \verb|changesequence|. The
726 constructor takes a list of attributes and the attribute changer
727 cycles through this list whenever a new attribute is requested.
728 This attribute changer is used to implement the following attribute
729 changers:
731 \begin{center}
732 \begin{tabular}{ll}
733 attribute changer&description\\
734 \hline
735 \texttt{changelinestyle}&iterates linestyles solid, dashed, dotted, dasheddotted\\
736 \texttt{changestrokedfilled}&iterates \texttt{(canvas.stroked(), canvas.filled())}\\
737 \texttt{changefilledstroked}&iterates \texttt{(canvas.filled(), canvas.stroked())}\\
738 \end{tabular}
739 \end{center}
741 The class \verb|changesymbol| can be used to cycle throu symbols and it
742 provides already various specialized classes as class variables. To
743 loop over all available symbols (cross, plus, square, triangle,
744 circle, and diamond) the equal named class variables can be used. They
745 start at that symbol they are named of. Thus \verb|changesymbol.cross()|
746 cycles throu the sequence starting at the cross symbol. Furthermore
747 there are four class variables called \verb|squaretwice|,
748 \verb|triangletwice|, \verb|circletwice|, and \verb|diamondtwice|.
749 They cycle throu the four fillable symbols, but returning the symbols
750 twice before they go on to the next one. They are intented to be used
751 in combination with \verb|changestrokedfilled| and
752 \verb|changefilledstroked|.
754 \section{Keys}
756 Graph keys can be created by instances of the class \verb|key|. Its
757 constructor takes the following keyword arguments:
759 \medskip
760 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
761 argument name&description\\
762 \hline
763 \texttt{dist}&(vertical) distance between the key entries (visual length); default: \texttt{"0.2 cm"}\\
764 \texttt{pos}&\texttt{"tr"} (top right; default), \texttt{"br"} (bottom right), \texttt{"tl"} (top left), \texttt{"bl"} (bottom left)\\
765 \texttt{hdist}&horizontal distance of the key (visual length); default: \texttt{"0.6 cm"}\\
766 \texttt{vdist}&vertical distance of the key (visual length); default: \texttt{"0.4 cm"}\\
767 \texttt{hinside}&align horizonally inside to the graph (boolean); default: \texttt{1}\\
768 \texttt{vinside}&align vertically inside to the graph (boolean); default: \texttt{1}\\
769 \texttt{symbolwidth}&width reserved for the symbol (visual length); default: \texttt{"0.5 cm"}\\
770 \texttt{symbolheight}&height reserved for the symbol (visual length); default: \texttt{"0.25 cm"}\\
771 \texttt{symbolspace}&distance between symbol and text (visual length); default: \texttt{"0.2 cm"}\\
772 \texttt{textattrs}&text attributes (a list or a single entry); default: \texttt{text.vshift.mathaxis}\\
773 \end{tabularx}
774 \medskip
776 The data description to be printed in the graph key is given by the
777 title of the data drawn.
779 \section{X-Y-Graph}
781 The class \verb|graphxy| draws standard x-y-graphs. It is a subcanvas
782 and can thus be just inserted into a canvas. The x-axes are named
783 \verb|x|, \verb|x2|, \verb|x3|, \dots and equally the y-axes. The
784 number of axes is not limited. All odd numbered axes are plotted at
785 the bottom (for x axes) and at the left (for y axes) and all even
786 numbered axes are plotted opposite to them. The lower numbers are
787 closer to the graph.
789 The constructor of \verb|graphxy| takes axes as named parameters where
790 the parameter name is an axis name as just described. Those parameters
791 refer to an axis instance as they where described in
792 section~\ref{graph:axes}. When no \verb|x| or \verb|y| is provided,
793 they are automatically set to instances of \verb|linaxis|. When no
794 \verb|x2| or \verb|y2| axes are given they are initialized as standard
795 linkaxis to the axis \verb|x| and \verb|y|. However, you can turn off
796 the automatism by setting those axes explicitly to \verb|None|.
798 However, the constructor takes some more attributes listed in the
799 following table:
801 \medskip
802 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
803 argument name&default&description\\
804 \hline
805 \texttt{xpos}&\texttt{"0"}&x position of the graph (user length)\\
806 \texttt{ypos}&\texttt{"0"}&y position of the graph (user length)\\
807 \texttt{width}&\texttt{None}&width of the graph area (axes are outside of that range)\\
808 \texttt{height}&\texttt{None}&as abovem, but for the height\\
809 \texttt{ratio}&\texttt{goldenrule}&width/height ratio when only a width or height is provided\\
810 \texttt{backgroundattrs}&\texttt{None}&background attributes for the graph area\\
811 \texttt{axisdist}&\texttt{"0.8 cm"}&distance between axis (visual length)\\
812 \texttt{key}&\texttt{None}&\texttt{key} instance for an automatic graph key\\
813 \end{tabularx}
814 \medskip
816 After a graph is constructed, data can be plotted via the \verb|plot|
817 method. The first argument should be an instance of the data providing
818 classes described in section~\ref{graph:data}. This first parameter
819 can also be a list of those instances when you want to iterate the
820 style you explicitly provide as a second parameter to the plot method.
821 The plot method returns the plotinfo instance (or a list of plotinfo
822 instances when a data list was provided). The plotinfo class has
823 attributes \verb|data| and \verb|style|, which provide access to the
824 plotted data and the style, respectively. Just as an example, from the
825 style you can access the path of the drawed line, fill areas with it
826 etc.
828 After the plot method was called once or several times, you may
829 explicitly call the method \verb|finish|. Most of the graphs
830 functionallity becomes available just after (partially) finishing the
831 graph. A partial finish can even modify the order in which a graph
832 performs its drawing process. By default the five methods
833 \verb|dolayout|, \verb|dobackground|, \verb|doaxis|, \verb|dodata|,
834 and \verb|dokey| are called in that order. The method \verb|dolayout|
835 must always be called first, but this is internally ensured once you
836 call any of the routines yourself. After \verb|dolayout| gets called,
837 the method \verb|plot| can not be used anymore.
839 To get a position within a graph as a tuple out of some axes values,
840 the method \verb|pos| can be used. It takes two values for a position
841 at the x and y axis. By default, the axes named \verb|x| or \verb|y|
842 are used, but this is changed when the keyword arguments \verb|xaxis|
843 and \verb|yaxis| are set to other axes. The graph axes are available
844 by their name using the dictionary \verb|axes|. Each axis has a method
845 \verb|gridpath| which is set by the graph. It returns a path of a grid
846 line for a given position at the axis.
848 To manually add a graph key, use the \verb|addkey| method, which takes
849 a \verb|key| instance first followed by several \verb|plotinfo|
850 instances.