- renamed: palette->gradient, functionpalette->functiongradient, linearpalette->linea...
[PyX/mjg.git] / examples / graphs / change.txt
blobee5b05401c04244a8e3175a77f7d7320831b6472
1 Plotting more than one data set and adding a graph key
3 In this example we demonstrate how to plot more than one data set in a graph.
4 Furthermore, adding a graph key labelling the data is explained. ...
6 In order to display more than one data set, we pass a list of data sets to the
7 `plot` method of the graph. In the present case, we contruct this list out of
8 three lists of `graph.data.function` instances. For each data set we also
9 set a title using the corresponding keyword argument of the data class.
11 For a more colorful output, we pass the `color.gradient.Rainbow` color gradient
12 to the `graph.style.line` class. PyX then automatically chooses color spanning
13 the whole range of the rainbow gradient.
15 ! If you look at the output, you will notice that not only the colors are
16 cycled through, but also the line style changes. The reason for this behavior
17 is that the default line attributes of the `graph.style.line` style contain an
18 `attr.changelist` comprising a couple of different line styles. When you pass
19 additional line attributes, these are appended to the default attributes (this
20 is generally the case in PyX). Consequently, you get a change of both the
21 color and the line style. If you only want to change the color, either
22 pass the desired line style explicitly, i.e., use
23     graph.style.line([style.linestyle.solid, color.gradient.Rainbow])
24 or clear a previous setting of the line style using the `clear` attribute
25 of the corresponding class:
26     graph.style.line([style.linestyle.clear, color.gradient.Rainbow])
28 !! It is also possible to call the `plot` method several times. Note that the
29 changing of the styles is also performed when the style instances are used on
30 several plot commands within the same graph as long as the same set of style
31 instances are passed at the `plot` method calls.
33 Finally, when plotting more than one data set you might want to label them in
34 your graph. We already have passed titles identifying each data set, so we only
35 have to add a graph key. This is done by passing a `graph.key.key` instance as
36 the `key` keyword argument to the graph. Usually, you only need to specify the
37 position of the key using the `pos` argument of the `graph.key.key`
38 constructor. The syntax should be self-explaining; here we use `br` to put
39 the key at the bottom-right position of the graph. In order to save some
40 space, we furthermore decreases the distance between the key entries a little
41 bit by passing a value of 0.1 to the `dist` argument.