valign.middle
[PyX/mjg.git] / manual / graph.tex
blobbe4f20b107220058d8f787ac66efb50156f637f0
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 (the graph itself is its canvas, that can be inserted into another
31 canvas). By that, all other components can be reused for different
32 graph geometries. The interfaces between the components are documented
33 in docstrings of interface classes in the source. The interface
34 technique is used for documentation purposes only. For the user, the
35 most important informations (as described in the following) are the
36 parameters of the constructors of the various implementations of those
37 interface. They are documented in docstrings of the constructors of
38 the classes. While effort of clearing and documenting is still in
39 progress, some parts are already nicely documented as you may see by
40 using \verb|pydoc|.
42 \section{Axes}
43 \label{graph:axes}
45 A common feature of a graph are axes. An axis is responsible for the
46 conversion of values to graph coordinates. There are predefined axis
47 types, namely:
48 \begin{center}
49 \begin{tabular}{ll}
50 axis type&description\\
51 \hline
52 \texttt{linaxis}&linear axis\\
53 \texttt{logaxis}&logarithmic axis\\
54 \end{tabular}
55 \end{center}
57 Further axes types are available to support axes splitting and bar
58 graphs (other axes types might be added in the future as well), but
59 they behave quite different from the generic case and are thus
60 described separately below.
62 \subsection{Axes properties}
64 Global properties of an axis are set as named parameters in the axis
65 constructor. Both, the \verb|linaxis| and the \verb|logaxis|, have the
66 same set of named parameters listed in the following table:
68 \medskip
69 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
70 argument name&description\\
71 \hline
72 \texttt{title}&axis title\\
73 \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\\
74 \texttt{max}&as above, but for the maximum\\
75 \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\\
76 \texttt{divisor}&numerical divisor for the axis partitioning; default: \texttt{1}\\
77 \texttt{suffix}&a suffix to indicate the divisor within an automatic axis labeling\\
78 \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)\\
79 \texttt{datavmax}&as above, but for the maximum; default: \texttt{0.95} (or \texttt{1}, when max is present)\\
80 \texttt{tickvmin}&minimal graph coordinate for placing ticks to the axis; default: \texttt{0}\\
81 \texttt{tickvmax}&as above, but for the maximum; default: \texttt{1}\\
82 \texttt{density}&density parameter for the axis partition rating\\
83 \texttt{maxworse}&number of trials with worse tick rating before giving up; default: \texttt{2}\\
84 \texttt{painter}&axis painter (described below)\\
85 \texttt{texter}&texter for the axis labels (described below)\\
86 \texttt{part}&axis partition (described below)\\
87 \texttt{rater}&partition rater (described below)\\
88 \end{tabularx}
89 \medskip
91 \subsection{Partitioning of axes}
93 The definition of ticks and labels appropriate to an axis range is
94 called partitioning. The axis partioning within \PyX{} uses rational
95 arithmetics, which avoids any kind of rounding problems to the cost of
96 performance. The class \verb|frac| supplies a rational number. It can
97 be initialized by another \verb|frac| instance, a tuple of integers
98 (called enumerator and denominator), a float (which gets converted
99 into a frac with a finite resolution \verb|floatprecision| of 10
100 digits per default) or a string with infinite precision (like
101 "1.2345e-100" or even "1/3"). However, a partitioning is composed out
102 of a sorted list of ticks, where the class \verb|tick| is derived from
103 \verb|frac| and has additional properties called \verb|ticklevel|,
104 \verb|labellevel|, \verb|label| and \verb|labelattrs|. When the
105 ticklevel or the labellevel is \verb|None|, it just means not present,
106 \verb|0| means tick or label, respectively, \verb|1| means subtick or
107 sublevel and so on. When \verb|labellevel| is not \verb|None|, a
108 \verb|label| might be explicitly given, which will get used as the
109 text of that label. Otherwise the axis painter has to create an
110 appropriate text for the label. The \verb|labelattrs| might specify
111 some attributes for the label to be used by the \verb|text| method of
112 an \verb|texrunner| instance.
114 You can pass a list of \verb|tick| instance to the \verb|part|
115 argument of an axis. By that you can place ticks whereever you want.
116 Additionally you can use a partitioner to create ticks appropriate to
117 the axis range. This can be done by manually specifying distances
118 between ticks, subticks and so on. Alternatively there are automatic
119 axis partitioners available, which provide different partitions and
120 the rating of those different partitions by the \verb|rater| become
121 crutial. Note, that you can combine manually set ticks and a
122 partitioner in the \verb|part| argument of an axis.
124 \subsubsection{Partitioning of linear axes}
126 The class \verb|linpart| creates a linear partition as described by
127 named parameters of the constructor:
129 \medskip
130 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
131 argument name&default&description\\
132 \hline
133 \texttt{tickdist}&\texttt{None}&distance between ticks, subticks, etc. (see comment below); when the parameter is \texttt{None}, ticks will get placed at labels\\
134 \texttt{labeldist}&\texttt{None}&distance between labels, sublabels, etc. (see comment below); when the parameter is \texttt{None}, labels will get placed at ticks\\
135 \texttt{labels}&\texttt{None}&set the text for the labels manually\\
136 \texttt{extendtick}&\texttt{0}&allow for a range extention to include the next tick of the given level\\
137 \texttt{extendlabel}&\texttt{None}&as above, but for labels\\
138 \texttt{epsilon}&\texttt{1e-10}&allow for exceeding the range by that relative value\\
139 \end{tabularx}
140 \medskip
142 The \verb|ticks| and \verb|labels| can either be a list or just a
143 single entry. When a list is provided, the first entry stands for
144 the tick or label, respectively, the second for the subtick or
145 sublabel, and so on. The entries are passed to the constructor of a
146 frac instance, e.g. there can be tuples (enumerator, denominator),
147 strings, floats, etc.
149 \subsubsection{Partitioning of logarithmic axes}
151 The class \verb|logpart| create a logarithmic partition. The
152 parameters of the constructor of the class \verb|logpart| are quite
153 simular to the parameters of \verb|linpart| discussed above. Instead
154 of the parameters \verb|tickdist| and \verb|labeldist| the parameters
155 \verb|tickpos| and \verb|labelpos| are present. All other parameters
156 of \verb|logpart| do not differ in comparision to \verb|linpart|. The
157 \verb|tickdist| and \verb|labeldist| parameters take either a single
158 \verb|preexp| instance or a list of \verb|preexp| instances, where the
159 first stands for the ticks (labels), the second for subticks
160 (sublabels) and so on. A \verb|preexp| instance contains a list of
161 \verb|pres|, which are \verb|frac| instances defining some positions,
162 say $p_i$. Furthermore there is a \verb|frac| instance called
163 \verb|exp|, say $e$. Valid tick and label positions are then given by
164 $s^np_i$, where $n$ is an integer.
166 \begin{center}
167 \begin{tabular}{ll}
168 name&values it descibes\\
169 \hline
170 \texttt{pre1exp5}&1 and multiple of $10^5$\\
171 \texttt{pre1exp4}&1 and multiple of $10^4$\\
172 \texttt{pre1exp3}&1 and multiple of $10^3$\\
173 \texttt{pre1exp2}&1 and multiple of $10^2$\\
174 \texttt{pre1exp}&1 and multiple of $10$\\
175 \texttt{pre125exp}&1, 2, 5 and multiple of $10$\\
176 \texttt{pre1to9exp}&1, 2, \dots, 9 and multiple of $10$\\
177 \end{tabular}
178 \end{center}
180 \subsubsection{Automatic partitioning of linear axes}
182 When no explicit axis partitioner is given in the constructor argument
183 \verb|part| of an linear axis, it is initialized with an automatic
184 partitioning scheme for linear axes. This scheme is provided by the
185 class \verb|autolinpart|, where the constructor takes the following
186 arguments:
188 \medskip
189 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
190 argument name&default&description\\
191 \hline
192 \texttt{variants}&\texttt{defaultvariants}&list of possible values for the ticks parameter of \texttt{linpart} (labels are placed at the position of ticks)\\
193 \texttt{extendtick}&\texttt{0}&allow for a range extention to include the next tick of the given level\\
194 \texttt{epsilon}&\texttt{1e-10}&allow for exceeding the range by that relative value\\
195 \end{tabularx}
196 \medskip
198 The default value for the argument \verb|variants|, namely
199 \verb|defaultvariants|, is defined as a class variable of
200 \verb|autolinpart| and has the value \texttt{((frac(1, 1), frac(1,
201 2)), (frac(2, 1), frac(1, 1)), (frac(5, 2), frac(5, 4)), (frac(5, 1),
202 frac(5, 2)))}. This implies, that the automatic axis partitioning
203 scheme allows for partitions using (ticks, subticks) with at distances
204 (1, 1/2), (2, 1), (5/2, 5/4), (5, 5/2). This list must be sorted by
205 the number of ticks the entries will lead to. The given fractions are
206 automatically multiplied or divided by 10 in order to fit better to
207 the axis range. Therefore those additional partitioning possibilities
208 (infinte possibilities) must not be given explicitly.
210 \subsubsection{Automatic partitioning of logarithmic axes}
212 When no explicit axis partitioning is given in the constructor
213 argument \verb|part| of an logarithmic axis, it is initialized with an
214 automatic partitioning schemes for logarithmic axes. This scheme is
215 provided by the class \verb|autologpart|, where the constructor takes
216 the following arguments:
218 \medskip
219 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
220 argument name&default&description\\
221 \hline
222 \texttt{variants}&\texttt{defaultvariants}&list of pairs with possible values for the ticks and labels parameters of \texttt{logpart}\\
223 \texttt{extendtick}&\texttt{0}&allow for a range extention to include the next tick of the given level\\
224 \texttt{extendlabel}&\texttt{None}&as above, but for labels\\
225 \texttt{epsilon}&\texttt{1e-10}&allow for exceeding the range by that relative value\\
226 \end{tabularx}
227 \medskip
229 The default value for the argument \verb|variants|, namely
230 \verb|defaultvariants|, is defined as a class variable of
231 \verb|autologpart| and has the value:
232 \begin{verbatim}
233 (((pre1exp, pre1to9exp), # ticks & subticks,
234 (pre1exp, pre125exp)), # labels & sublevels
235 ((pre1exp, pre1to9exp), None), # ticks & subticks, labels=ticks
236 ((pre1exp2, pre1exp), None), # ticks & subticks, labels=ticks
237 ((pre1exp3, pre1exp), None), # ticks & subticks, labels=ticks
238 ((pre1exp4, pre1exp), None), # ticks & subticks, labels=ticks
239 ((pre1exp5, pre1exp), None)) # ticks & subticks, labels=ticks
240 \end{verbatim}
241 As for the \verb|autolinaxis|, this list must be sorted by the number
242 of ticks the entries will lead to.
244 \subsubsection{Rating of axes partitionings}
246 When an axis partitioning scheme returns several partitioning
247 possibilities, the partitions are rated by an instance of a rater
248 class provided as the parameter \verb|rater| at the axis constructor.
249 It is used to calculate a positive rating number for a given axis
250 partitioning. In the end, the lowest rated axis partitioning gets
251 used.
253 The rating consists of two steps. The first takes into account only
254 the number of ticks, subticks, labels and so on in comparison to an
255 optimal number. Additionally, the transgression of the axis range by
256 ticks and labels is taken into account. This rating leads to a
257 preselection of possible partitions. In the second step the layout of
258 a partition gets acknowledged by rating the distance of the labels to
259 each other. Thereby partitions with overlapping labels get quashed
260 out.
262 The class \verb|axisrater| implements a rating with quite some
263 parameters specifically adjusted to linear and logarithmic axes. A
264 detailed description of the hole system goes beyond the scope of that
265 manual. Take your freedom and have a look at the \PyX{} source code if
266 you wish to adopt the rating to personal preferences.
268 The overall optimal partition properties, namely the density of ticks
269 and labels, can be easily adjusted by the single parameter
270 \verb|density| of the axis constructor. The rating is
271 adjusted to the default densitiy value of \verb|1|, but modifications
272 of this parameter in the range of 0.5 (for less ticks) to 2 or even 3
273 (for more ticks) might be usefull.
275 \subsection{Creating label text}
277 When a partition is created, the typical situation is that some of the
278 ticks have a \verb|labellevel| not equal to \verb|None| but there is
279 no \verb|label| (a string) defined to be printed at this tick. The
280 task of a \verb|texter| is to create those label strings for a given
281 list of ticks. There are different \verb|texter| classes creating
282 different label strings.
284 \subsubsection{Decimal numbers}
286 The class \verb|decimaltexter| creates decimal labels. The format of
287 the labels can be configured by numerous arguments of the constructor
288 listed in the following table:
290 \medskip
291 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
292 argument name&default&description\\
293 \hline
294 \texttt{prefix}&\texttt{""}&string to be inserted in front of the number\\
295 \texttt{infix}&\texttt{""}&string to be inserted between the plus or minus sign and the number\\
296 \texttt{suffix}&\texttt{""}&string to be inserted after the number\\
297 \texttt{equalprecision}&\texttt{0}&forces a common number of digits after the comma\\
298 \texttt{decimalsep}&\texttt{"."}&decimal separator\\
299 \texttt{thousandsep}&\texttt{""}&thousand separator\\
300 \texttt{thousandthpartsep}&\texttt{""}&thousandth part separator\\
301 \texttt{plus}&\texttt{""}&plus sign\\
302 \texttt{minus}&\texttt{"-"}&minus sign\\
303 \texttt{period}&\texttt{r"\textbackslash overline\{\%s\}"}&format string to indicate a period\\
304 \texttt{labelattrs}&\texttt{text.mathmode}&a single attribute or a list of attributes to be added to the labelattrs\\
305 \end{tabularx}
306 \medskip
308 \subsubsection{Decimal numbers with an exponential}
310 The class \verb|exponentialtexter| creates decimal labels with an
311 exponent. The format of the labels can be configured by numerous
312 arguments of the constructor listed in the following table:
314 \medskip
315 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
316 argument name&default&description\\
317 \hline
318 \texttt{plus}&\texttt{""}&plus sign for the exponent\\
319 \texttt{minus}&\texttt{"-"}&minus sign for the exponent\\
320 \texttt{mantissaexp}&\texttt{r"\{\{\%s\}\textbackslash cdot10\textasciicircum\{\%s\}\}"}&format string for manissa and exponent\\
321 \texttt{nomantissaexp}&\texttt{r"\{10\textbackslash\{\%s\}\}"}&format string when skipping a manissa equals 1\\
322 \texttt{minusnomantissaexp}&\texttt{r"\{-1\textbackslash\{\%s\}\}"}&format string when skipping a manstissa equals -1\\
323 \texttt{mantissamin}&\texttt{frac((1, 1))}&minimal value for the mantissa\\
324 \texttt{mantissamax}&\texttt{frac((10, 1))}&maximal value for the mantissa\\
325 \texttt{skipmantissa1}&\texttt{0}&skip mantissa equals 1\\
326 \texttt{skipallmantissa1}&\texttt{1}&skip mantissa when its always 1\\
327 \texttt{mantissatexter}&\texttt{decimaltexter()}&texter for the mantissa\\
328 \end{tabularx}
329 \medskip
331 \subsubsection{Decimal numbers without or with an exponential}
333 The class \verb|defaulttexter| creates decimal labels without or
334 with an exponent. As the name says, its used as the default texter.
335 The texter splits the tick list into two lists, one to be passed to a
336 decimal texter and another to be passed to an exponential texter. This
337 splitting is based on the two properties \verb|smallestdecimal| and
338 \verb|biggestdecimal|. See the following table for all available
339 arguments:
341 \medskip
342 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
343 argument name&default&description\\
344 \hline
345 \texttt{smallestdecimal}&\texttt{frac((1, 1000))}&the smallest number (ignoring the sign) where the decimal texter should be used\\
346 \texttt{biggestdecimal}&\texttt{frac((9999, 1))}&as above, but for the biggest number\\
347 \texttt{equaldecision}&\texttt{1}&either use the \texttt{decimaltexter} or the \texttt{exponentialtexter}\\
348 \texttt{decimaltexter}&\texttt{decimaltexter()}&texter withoud an exponential\\
349 \texttt{exponentialtexter}&\texttt{exponentialtexter()}&exponential with an exponential\\
350 \end{tabularx}
351 \medskip
353 \subsubsection{Rational numbers}
355 The class \verb|rationaltexter| creates rational labels. The format of
356 the labels can be configured by numerous arguments of the constructor
357 listed in the following table:
359 \medskip
360 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
361 argument name&default&description\\
362 \hline
363 \texttt{prefix}&\texttt{""}&string to be inserted in front of the rational\\
364 \texttt{infix}&\texttt{""}&string to be inserted between the plus or minus sign and the rational\\
365 \texttt{suffix}&\texttt{""}&string to be inserted after the rational\\
366 \texttt{enumprefix}&\texttt{""}&as \texttt{prefix} but for the enumerator\\
367 \texttt{enuminfix}&\texttt{""}&as \texttt{infix} but for the enumerator\\
368 \texttt{enumsuffix}&\texttt{""}&as \texttt{suffix} but for the enumerator\\
369 \texttt{denomprefix}&\texttt{""}&as \texttt{prefix} but for the denominator\\
370 \texttt{denominfix}&\texttt{""}&as \texttt{infix} but for the denominator\\
371 \texttt{denomsuffix}&\texttt{""}&as \texttt{suffix} but for the denominator\\
372 \texttt{plus}&\texttt{""}&plus sign\\
373 \texttt{minus}&\texttt{"-"}&minus sign\\
374 \texttt{minuspos}&\texttt{0}&position of the minus: \texttt{0} -- in front of the fraction, \texttt{1} -- in front of the enumerator, \texttt{-1} -- in front of the denominator\\
375 \texttt{over}&\texttt{r"\{\{\%s\}\textbackslash over\{\%s\}\}"}&format string for the fraction\\
376 \texttt{equaldenom}&\texttt{0}&usually, the enumerator and the denominator are canceled; if set, take the least common multiple of all denominators\\
377 \texttt{skip1}&\texttt{1}&skip printing the fraction for \texttt{1} when there is a \texttt{prefix}, \texttt{infix}, or \texttt{suffix}\\
378 \texttt{skipenum0}&\texttt{1}&print \texttt{0} instead of a fraction when the enumerator is 0\\
379 \texttt{skipenum1}&\texttt{1}&as \texttt{skip1} but for the enumerator\\
380 \texttt{skipdenom1}&\texttt{1}&skip the denominator when it is \texttt{1} and there is no \texttt{denomprefix}, \texttt{denominfix}, or \texttt{denomsuffix}\\
381 \texttt{labelattrs}&\texttt{text.mathmode}&a single attribute or a list of attributes to be added to the labelattrs\\
382 \end{tabularx}
383 \medskip
385 \subsection{Painting of axes}
387 A major task for an axis is its painting. It is done by instances of
388 \verb|axispainter|, provided to the constructor of an axis as its
389 \verb|painter| argument. The constructor of the axis painter receives
390 a numerous list of named parameters to modify the axis look. A list of
391 parameters is provided in the following table:
393 \medskip
394 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
395 argument name&description\\
396 \hline
397 \texttt{innerticklengths}$^{1,4}$&tick length of inner ticks (visual length);\newline default: \texttt{axispainter.defaultticklengths}\\
398 \texttt{outerticklengths}$^{1,4}$&as before, but for outer ticks; default: \texttt{None}\\
399 \texttt{tickattrs}$^{2,4}$&stroke attributes for ticks; default: \texttt{()}\\
400 \texttt{gridattrs}$^{2,4}$&stroke attributes for grid lines; default: \texttt{None}\\
401 \texttt{zerolineattrs}$^{3,4}$&stroke attributes for a grid line at axis value 0; default: \texttt{()}\\
402 \texttt{baselineattrs}$^{3,4}$&stroke attributes for the axis baseline;\newline default: \texttt{canvas.linecap.square}\\
403 \texttt{labeldist}&label distance from axis (visual length); default: \texttt{"0.3 cm"}\\
404 \texttt{labelattrs}$^{2,4}$&text attributes for labels;\newline default: \texttt{(text.halign.center, text.vshift.mathaxis)}\\
405 \texttt{labeldirection}$^4$&relative label direction (see below); default: \texttt{None}\\
406 \texttt{labelhequalize}&set width of labels to its maximum (boolean); default: \texttt{0}\\
407 \texttt{labelvequalize}&set height and depth of labels to their maxima (boolean); default: \texttt{1}\\
408 \texttt{titledist}&title distance from labels (visual length); default: \texttt{"0.3 cm"}\\
409 \texttt{titleattrs}$^{3,4}$&text attributes for title; default: \texttt{(text.halign.center, text.vshift.mathaxis)}\\
410 \texttt{titledirection}$^4$&relative title direction (see below);\newline default: \texttt{paralleltext}\\
411 \texttt{titlepos}&title position in graph coordinates; default: \texttt{0.5}\\
412 \end{tabularx}
413 \medskip
415 $^1$
416 The parameter should be a list, where the entries are attributes
417 for the different levels. When the level is larger then the list
418 length, \verb|None| is assumed. When the parameter is not a list,
419 it is applied to all levels.\\
420 $^2$
421 The parameter should be a list of lists, where the entries are
422 attributes for the different levels. When the level is larger then the
423 list length, \verb|None| is assumed. When the parameter is not a
424 list of lists, it is applied to all levels.\\
425 $^3$
426 The parameter should be a list. When the parameter is not a
427 list, the parameter is interpreted as a list with a single
428 entry.\\
429 $^4$
430 The feature can be turned off by the value \verb|None|. Within
431 lists or lists of lists, the value \verb|None| might be
432 used to turn off the feature for some levels selectively.
433 \medskip
435 Relative directions for labels (\verb|labeldirection|) and titles
436 (\verb|titledirection|) are instances of \verb|rotatetext|. By that
437 the text direction is calculated relatively to the tick direction of
438 the axis and is added as an attribute of the text. The relative
439 direction provided by instances of the class \verb|rotatetext| prevent
440 upside down text by flipping it by 180 degrees. For convenience, the
441 two self-explanatory values \verb|rotatetext.parallel| and
442 \verb|rotatetext.orthogonal| are available, which are just instances of
443 rotatetext initializes by \verb|-90| degree and \verb|0|,
444 respectively.
446 \subsection{Linked axes}
448 Linked axes can be used whenever an axis should be repeated within a
449 single graph or even between different graphs although the intrinsic
450 meaning is to have only one axis plotted several times. Almost all
451 properties of a linked axis are supplied by the axis it is linked to
452 (you may call it the base axis), but some properties and methods might
453 be different. For the typical case (implemented by \verb|linkaxis|)
454 only the painter of the axis is exchanged together with some
455 simplified behaviour when finishing the axis (there is no need to
456 recalculate the axis partition etc.). The constructor of
457 \verb|linkaxis| takes the axis to be linked to as the first parameter
458 and in the named parameter \verb|painter| a new painter for the axis.
459 By default, \verb|linkaxispainter| is used, which differs from the
460 standard \verb|axispainter| by some default values for the arguments
461 only. Namely, the arguments \verb|zerolineattrs|, \verb|labelattrs|,
462 and \verb|titleattrs| are set to \verb|None| turing off these
463 features.
465 \subsection{Special purpose axes}
467 \subsubsection{Splitable axes}
469 Axes with breaks are created by instances of the class
470 \verb|splitaxis|. Its constructor takes the following parameters:
472 \medskip
473 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
474 argument name&description\\
475 \hline
476 (axis list)&a list of axes to be used as subaxes (this is the first parameter of the constructor; it has no name)\\
477 \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}\\
478 \texttt{splitdist}&gap of the axis break; default: \texttt{0.1}\\
479 \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}\\
480 \texttt{title}&axis title\\
481 \texttt{painter}&axis painter; default: \texttt{splitaxispainter()} (described below)\\
482 \end{tabularx}
483 \medskip
485 A split axis is build up from a list of ``subaxes''. Those subaxes
486 have to provide some range information needed to identify the subaxis
487 to be used out of a plain number (thus all axes minima and maxima has
488 to be set except for the two subaxes at the egde, where for the first
489 only the maximum is needed, while for the last only the minimum is
490 needed). The only point left is the description of the specialized
491 \verb|splitaxispainter|, where the constructor takes the following
492 parameters:
494 \medskip
495 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
496 argument name&description\\
497 \hline
498 \texttt{breaklinesdist}&(visual) distance between the break lines; default: \texttt{0.05}\\
499 \texttt{breaklineslength}&(visual) length of break lines; default: \texttt{0.5}\\
500 \texttt{breaklinesangle}&angle of the breakline with respect to the axis; default: \texttt{-60}\\
501 \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{()}\\
502 \end{tabularx}
504 Additionally, the painter takes parameters for the axis title
505 formatting like the standard axis painter class \verb|axispainter|.
506 (There is a common base class \verb|titleaxispainter| for that.) The
507 parameters are \verb|titledist|, \verb|titleattrs|,
508 \verb|titledirection|, and \verb|titlepos|.
510 \subsubsection{Bar axes}
512 Axes appropriate for bar graphs are created by instances of the class
513 \verb|baraxis|. Its constructor takes the following parameters:
515 \medskip
516 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
517 argument name&description\\
518 \hline
519 \texttt{subaxis}&baraxis can be recursive by having another axis as its subaxis; default: \texttt{None}\\
520 \texttt{multisubaxis}&contains another baraxis instance to be used to construct a new subaxes for each item (by that a nested bar axis with a different number of subbars at each bar can be created) ; default: \texttt{None}\\
521 \texttt{title}&axis title\\
522 \texttt{dist}&distance between bars (relative to the bar width); default: \texttt{0.5}\\
523 \texttt{firstdist}&distance of the first bar to the border; default: \texttt{0.5*dist}\\
524 \texttt{lastdist}&as before but for the last bar\\
525 \texttt{names}&tuple of name identifiers for bars; when set, no other identifiers are allowed; default: \texttt{None}\\
526 \texttt{texts}&dictionary translating names into label texts (otherwise just the names are used); default: \texttt{\{\}}\\
527 \texttt{painter}&axis painter; default: \texttt{baraxispainter} (described below)\\
528 \end{tabularx}
529 \medskip
531 In contrast to other axes, a bar axis uses name identifiers to
532 calculate a position at the axis. Usually, a style appropriate to a
533 bar axis (this is right now just the bar style) set those names out of
534 the data it recieves. However, the names can be forced and fixed.
536 Bar axes can be recursive. Thus for a given value, an appropriate
537 subaxis is choosen (usually another bar axis). Usually only a single
538 subaxis is needed, because it doesn't need to be painted and for each
539 value the same recursive subaxis transformation has to be applied.
540 This is achieved by using the parameter \verb|subaxis|. Alternatively
541 you may use the \verb|multisubaxis|. Here only a bar axis can be used.
542 Then the subaxes (note axes instead of axis) are painted as well
543 (however their painter can be set to not paint anything). For that,
544 duplications of the subaxis are created for each name. By that, each
545 subaxis can have different names, in particular different number of
546 names.
548 The only point left is the description of the specialized
549 \verb|baraxispainter|. It works quite similar to the
550 \verb|axispainter|. Thus the constructors have quite some parameters
551 in common, namely \verb|titledist|, \verb|titleattrs|,
552 \verb|titledirection|, \verb|titlepos|, and \verb|baselineattrs|.
553 Furthermore the parameters \verb|innerticklength| and
554 \verb|outerticklength| work like their counterparts in the
555 \verb|axispainter|, but only plain values are allowed there (no
556 lists). However, they are both \verb|None| by default and no ticks
557 get plotted. Then there is a hole bunch of name
558 attribute identifiers, namely \verb|namedist|, \verb|nameattrs|,
559 \verb|namedirection|, \verb|namehequalize|, \verb|namevequalize| which
560 are identical to their counterparts called \verb|label...| instead of
561 \verb|name...|. Last but not least, there is a parameter \verb|namepos|
562 which is analogous to \verb|titlepos| and set to \verb|0.5| by
563 default.
565 \section{Data}
566 \label{graph:data}
568 \subsection{List of points}
570 Instances of the class \verb|data| link together a \verb|datafile| (or
571 another instance of a class from the module \verb|data|) and a
572 \verb|style| (see below; default is \verb|symbol|). The link object is
573 needed in order to be able to plot several data from a singe file
574 without reading the file several times. However, for easy usage, it is
575 possible to provide just a filename instead of a \verb|datafile|
576 instance as the first argument to the constructor of the class
577 \verb|data| thus hiding the underlying \verb|datafile| instance
578 completely from view. This is the preferable solution as long as the
579 datafile gets used only once.
581 The additional parameters of the constructor of the class \verb|data|
582 are named parameters. The values of those parameters describe data
583 columns which are linked to the names of the parameters within the
584 style. The data columns can be identified directly via their number or
585 title, or by means of mathematical expression (as in the addcolumn
586 method of the class \verb|data| in the module \verb|data|; see
587 chapter~\ref{module:data}; indeed a addcolumn call takes place to
588 evaluate mathematical expressions once and for all).
590 The constructors keyword argument \verb|title| however does not
591 refer to a parameter of a style, but instead sets the title to be used
592 in an axis key.
594 \subsection{Functions}
596 The class \verb|function| provides data generation out of a functional
597 expression. The default style for function plotting is \verb|line|.
598 The constructor of \verb|function| takes an expression as the first
599 parameter. The expression must be a string with exactly one equal sign
600 (\verb|=|). At the left side the result axis identifier must be placed
601 and at the right side the expression must depend on exactly one
602 variable axis identifier. Hence, a valid expression looks like
603 \verb|"y=sin(x)"|. You can access own variables and functions by
604 providing them as a dictionary to the constructors \verb|context|
605 keyword argument.
607 Additional named parameters of the constructor are:
609 \medskip
610 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
611 argument name&default&description\\
612 \hline
613 \texttt{min}&\texttt{None}&minimal value for the variable parameter; when \texttt{None}, the axis data range will be used\\
614 \texttt{max}&\texttt{None}&as above, but for the maximum\\
615 \texttt{points}&\texttt{100}&number of points to be calculated\\
616 \texttt{parser}&\texttt{mathtree.parser()}&parser for the mathematical expression\\
617 \texttt{context}&\texttt{None}&dictionary of extern variables and functions\\
618 \texttt{title}&equal to the expression&title to be used in the graph key\\
619 \end{tabularx}
620 \medskip
622 The expression evaluation takes place at a linear raster on the
623 variable axis. More advanced methods (detection of rapidely changing
624 functions, handling of divergencies) are likely to be added in future
625 releases.
627 \subsection{Parametric functions}
629 The class \verb|paramfunction| provides data generation out of a
630 parametric representation of a function. The default style for
631 parametric function plotting is \verb|line|. The parameter list of the
632 constructor of \verb|paramfunction| starts with three parameters
633 describing the function parameter. The first parameter is a string,
634 namely the variable name. It is followed by a minimal and maximal
635 value to be used for that parameter. The next parameter contains an
636 expression assigning functions to the axis identifiers in a quite
637 pythonic tuple notation. As an example, such an expression could look
638 like \verb|"x, y = sin(k), cos(3*k)"|.
640 Additionally, the named parameters \verb|points|, \verb|parser|,
641 \verb|context|, and \verb|title| behave like their equally named
642 counterparts in \verb|function|.
644 \section{Styles}
645 \label{graph:styles}
647 Styles are used to draw data at a graph. A style determines what is
648 painted and how it is painted. Due to this powerfull approach there
649 are already some different styles available and the possibility to
650 introduce other styles opens even more prospects.
652 \subsection{Symbols}
654 The class \verb|symbol| can be used to plot symbols, errorbars and lines
655 configurable by parameters of the constructor. Providing \verb|None|
656 to attributes hides the according component.
658 \medskip
659 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
660 argument name&default&description\\
661 \hline
662 \texttt{symbol}&\texttt{changesymbol.cross()}&symbol to be used (see below)\\
663 \texttt{size}&\texttt{"0.2 cm"}&size of the symbol (visual length)\\
664 \texttt{symbolattrs}&\texttt{deco.stroked()}&draw attributes for the symbol\\
665 \texttt{errorscale}&\texttt{0.5}&size of the errorbar caps (relative to the symbol size)\\
666 \texttt{errorbarattrs}&\texttt{()}&stroke attributes for the errorbars\\
667 \texttt{lineattrs}&\texttt{None}&stroke attributes for the line\\
668 \end{tabularx}
669 \medskip
671 The parameter \verb|symbol| has to be a routine, which returns a path to
672 be drawn (e.g. stroked or filled). There are several such routines
673 already available in the class \verb|symbol|, namely \verb|cross|,
674 \verb|plus|, \verb|square|, \verb|triangle|, \verb|circle|, and
675 \verb|diamond|. Furthermore, changeable attributes might be used here
676 (like the default value \verb|changesymbol.cross|), see
677 section~\ref{graph:changeattrs} for details.
679 The attributes are available as class variables after plotting the
680 style for outside usage. Additionally, the variable \verb|path|
681 contains the path of the line (even when it wasn't plotted), which
682 might be used to get crossing points, fill areas, etc.
684 Valid data names to be used when providing data to symbols are listed
685 in the following table. The character \verb|X| stands for axis names
686 like \verb|x|, \verb|x2|, \verb|y|, etc.
688 \begin{center}
689 \begin{tabular}{ll}
690 data name&description\\
691 \hline
692 \texttt{X}&position of the symbol\\
693 \texttt{Xmin}&minimum for the errorbar\\
694 \texttt{Xmax}&maximum for the errorbar\\
695 \texttt{dX}&relative size of the errorbar: \texttt{Xmin, Xmax = X-dX, X+Xd}\\
696 \texttt{dXmin}&relative minimum \texttt{Xmin = X-dXmin}\\
697 \texttt{dXmax}&relative maximum \texttt{Xmax = X+dXmax}\\
698 \end{tabular}
699 \end{center}
701 \subsection{Lines}
703 The class \verb|line| is inherited from the class \verb|symbol| and
704 restricted itself to line drawing. The constructor takes only the
705 \verb|lineattrs| keyword argment, which is by default set to
706 \verb|(changelinestyle(), style.linejoin.round)|. The other features
707 of the symbol style are turned off.
709 \subsection{Rectangles}
711 The class \verb|rect| draws filled rectangles into a graph. The size
712 and the position of the rectangles to be plotted can be provided by
713 the same data names like for the errorbars of the class \verb|symbol|.
714 Indeed, the class \verb|symbol| reuses most of the symbol code by
715 inheritance, while modifying the errorbar look into a colored filled
716 rectangle and turing off the symbol itself.
718 The color to be used for the filling of the rectangles is taken from a
719 palette provided to the constructor by the named parameter
720 \verb|palette| (default is \verb|color.palette.Gray|). The data
721 name \verb|color| is used to select the color out of this palette.
723 \subsection{Texts}
725 Another style to be used within graphs is the class \verb|text|, which
726 adds the output of text to the class \verb|symbol|. The text
727 position relative to the symbol is defined by the two named
728 parameters \verb|textdx| and \verb|textdy| having a default of
729 \verb|"0 cm"| and \verb|"0.3 cm"|, respectively, which are by default
730 interpreted as visual length. A further named parameter
731 \verb|textattrs| may contain a list of text attributes (or just a
732 single attribute). The default for this parameter is
733 \verb|text.halign.center|. Furthermore the constructor of this class
734 allows all other attributes of the class \verb|symbol|.
736 \subsection{Arrows}
738 The class \verb|arrow| can be used to plot small arrows into a graph
739 where the size and direction of the arrows has to be given within the
740 data. The constructor of the class takes the following parameters:
742 \medskip
743 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
744 argument name&default&description\\
745 \hline
746 \texttt{linelength}&\texttt{"0.2 cm"}&length of a the arrow line (visual length)\\
747 \texttt{arrowattrs}&\texttt{()}&stroke attributes\\
748 \texttt{arrowsize}&\texttt{"0.1 cm"}&size of the arrow (visual length)\\
749 \texttt{arrowdict}&\texttt{\{\}}&attributes to be used in the \texttt{earrow} constructor\\
750 \texttt{epsilon}&1e-10&smallest allowed arrow size factor for a arrow to become plotted (avoid numerical instabilities)\\
751 \end{tabularx}
752 \medskip
754 The arrow allows for data names like the symbol and introduces
755 additionally the data names \verb|size| for the arrow size (as an
756 multiplicator for the sizes provided to the constructor) and
757 \verb|angle| for the arrow direction (in degree).
759 \subsection{Bars}
761 The class \verb|bar| must be used in combination with an
762 \verb|baraxis| in order to create bar plots. The constructor takes the
763 following parameters:
765 \medskip
766 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
767 argument name&description\\
768 \hline
769 \texttt{fromzero}&bars start at zero (boolean); default: \texttt{1}\\
770 \texttt{stacked}&stack bars (boolean/integer); for values bigger than 1 it is the number of bars to be stacked; default: \texttt{0}\\
771 \texttt{skipmissing}&skip entries in the bar axis, when datapoints are missing; default: \texttt{1}\\
772 \texttt{xbar}&bars parallel to the graphs x-direction (boolean); default: \texttt{0}\\
773 \texttt{barattrs}&fill attributes; default: \texttt{(deco.stroked(color.gray.black), changecolor.Rainbow())}\\
774 \end{tabularx}
776 Additionally, the bar style takes two data names appropriate to the
777 graph (like \verb|x|, \verb|x2|, and \verb|y|).
779 \subsection{Iterateable style attributes}
780 \label{graph:changeattrs}
782 The attributes provided to the constructors of styles can usually
783 handle so called iterateable attributes, which are changing itself
784 when plotting several data sets. Iterateable attributes can be easily
785 written, but there are already some iterateable attributes available
786 for the most common cases. For example a color change is done by
787 instances of the class \verb|colorchange|, where the constructor takes
788 a palette. Applying this attribute to a style and using this style at
789 a list of data, the color will get changed lineary along the
790 palette from one end to the other. The class \verb|colorchange|
791 includes inherited classes as class variables, which are called like
792 the color palettes shown in appendix~\ref{palettename}. For them the
793 default palette is set to the appropriate color palette.
795 Another attribute changer is called \verb|changesequence|. The
796 constructor takes a list of attributes and the attribute changer
797 cycles through this list whenever a new attribute is requested.
798 This attribute changer is used to implement the following attribute
799 changers:
801 \begin{center}
802 \begin{tabular}{ll}
803 attribute changer&description\\
804 \hline
805 \texttt{changelinestyle}&iterates linestyles solid, dashed, dotted, dashdotted\\
806 \texttt{changestrokedfilled}&iterates \texttt{(deco.stroked(), deco.filled())}\\
807 \texttt{changefilledstroked}&iterates \texttt{(deco.filled(), deco.stroked())}\\
808 \end{tabular}
809 \end{center}
811 The class \verb|changesymbol| can be used to cycle throu symbols and it
812 provides already various specialized classes as class variables. To
813 loop over all available symbols (cross, plus, square, triangle,
814 circle, and diamond) the equal named class variables can be used. They
815 start at that symbol they are named of. Thus \verb|changesymbol.cross()|
816 cycles throu the list starting at the cross symbol. Furthermore
817 there are four class variables called \verb|squaretwice|,
818 \verb|triangletwice|, \verb|circletwice|, and \verb|diamondtwice|.
819 They cycle throu the four fillable symbols, but returning the symbols
820 twice before they go on to the next one. They are intented to be used
821 in combination with \verb|changestrokedfilled| and
822 \verb|changefilledstroked|.
824 \section{Keys}
826 Graph keys can be created by instances of the class \verb|key|. Its
827 constructor takes the following keyword arguments:
829 \medskip
830 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
831 argument name&description\\
832 \hline
833 \texttt{dist}&(vertical) distance between the key entries (visual length); default: \texttt{"0.2 cm"}\\
834 \texttt{pos}&\texttt{"tr"} (top right; default), \texttt{"br"} (bottom right), \texttt{"tl"} (top left), \texttt{"bl"} (bottom left)\\
835 \texttt{hdist}&horizontal distance of the key (visual length); default: \texttt{"0.6 cm"}\\
836 \texttt{vdist}&vertical distance of the key (visual length); default: \texttt{"0.4 cm"}\\
837 \texttt{hinside}&align horizonally inside to the graph (boolean); default: \texttt{1}\\
838 \texttt{vinside}&align vertically inside to the graph (boolean); default: \texttt{1}\\
839 \texttt{symbolwidth}&width reserved for the symbol (visual length); default: \texttt{"0.5 cm"}\\
840 \texttt{symbolheight}&height reserved for the symbol (visual length); default: \texttt{"0.25 cm"}\\
841 \texttt{symbolspace}&distance between symbol and text (visual length); default: \texttt{"0.2 cm"}\\
842 \texttt{textattrs}&text attributes (a list or a single entry); default: \texttt{text.vshift.mathaxis}\\
843 \end{tabularx}
844 \medskip
846 The data description to be printed in the graph key is given by the
847 title of the data drawn.
849 \section{X-Y-Graph}
851 The class \verb|graphxy| draws standard x-y-graphs. It is a subcanvas
852 and can thus be just inserted into a canvas. The x-axes are named
853 \verb|x|, \verb|x2|, \verb|x3|, \dots and equally the y-axes. The
854 number of axes is not limited. All odd numbered axes are plotted at
855 the bottom (for x axes) and at the left (for y axes) and all even
856 numbered axes are plotted opposite to them. The lower numbers are
857 closer to the graph.
859 The constructor of \verb|graphxy| takes axes as named parameters where
860 the parameter name is an axis name as just described. Those parameters
861 refer to an axis instance as they where described in
862 section~\ref{graph:axes}. When no \verb|x| or \verb|y| is provided,
863 they are automatically set to instances of \verb|linaxis|. When no
864 \verb|x2| or \verb|y2| axes are given they are initialized as standard
865 linkaxis to the axis \verb|x| and \verb|y|. However, you can turn off
866 the automatism by setting those axes explicitly to \verb|None|.
868 However, the constructor takes some more attributes listed in the
869 following table:
871 \medskip
872 \begin{tabularx}{\linewidth}{ll>{\raggedright\arraybackslash}X}
873 argument name&default&description\\
874 \hline
875 \texttt{xpos}&\texttt{"0"}&x position of the graph (user length)\\
876 \texttt{ypos}&\texttt{"0"}&y position of the graph (user length)\\
877 \texttt{width}&\texttt{None}&width of the graph area (axes are outside of that range)\\
878 \texttt{height}&\texttt{None}&as abovem, but for the height\\
879 \texttt{ratio}&\texttt{goldenrule}&width/height ratio when only a width or height is provided\\
880 \texttt{backgroundattrs}&\texttt{None}&background attributes for the graph area\\
881 \texttt{axisdist}&\texttt{"0.8 cm"}&distance between axis (visual length)\\
882 \texttt{key}&\texttt{None}&\texttt{key} instance for an automatic graph key\\
883 \end{tabularx}
884 \medskip
886 After a graph is constructed, data can be plotted via the \verb|plot|
887 method. The first argument should be an instance of the data providing
888 classes described in section~\ref{graph:data}. This first parameter
889 can also be a list of those instances when you want to iterate the
890 style you explicitly provide as a second parameter to the plot method.
891 The plot method returns the plotinfo instance (or a list of plotinfo
892 instances when a data list was provided). The plotinfo class has
893 attributes \verb|data| and \verb|style|, which provide access to the
894 plotted data and the style, respectively. Just as an example, from the
895 style you can access the path of the drawed line, fill areas with it
896 etc.
898 After the plot method was called once or several times, you may
899 explicitly call the method \verb|finish|. Most of the graphs
900 functionallity becomes available just after (partially) finishing the
901 graph. A partial finish can even modify the order in which a graph
902 performs its drawing process. By default the five methods
903 \verb|dolayout|, \verb|dobackground|, \verb|doaxis|, \verb|dodata|,
904 and \verb|dokey| are called in that order. The method \verb|dolayout|
905 must always be called first, but this is internally ensured once you
906 call any of the routines yourself. After \verb|dolayout| gets called,
907 the method \verb|plot| can not be used anymore.
909 To get a position within a graph as a tuple out of some axes values,
910 the method \verb|pos| can be used. It takes two values for a position
911 at the x and y axis. By default, the axes named \verb|x| or \verb|y|
912 are used, but this is changed when the keyword arguments \verb|xaxis|
913 and \verb|yaxis| are set to other axes. The graph axes are available
914 by their name using the dictionary \verb|axes|. Each axis has a method
915 \verb|gridpath| which is set by the graph. It returns a path of a grid
916 line for a given position at the axis.
918 To manually add a graph key, use the \verb|addkey| method, which takes
919 a \verb|key| instance first followed by several \verb|plotinfo|
920 instances.