Date: 2006-05-21 08:16:32 -0700 (Sun, 21 May 2006)
more graphs example work
--- trunk/pyx/examples/graphs/INDEX 2006-05-20 15:46:35 UTC (rev 2744)
+++ trunk/pyx/examples/graphs/INDEX 2006-05-21 15:16:32 UTC (rev 2745)
@@ -1,4 +1,5 @@
--- trunk/pyx/examples/graphs/function.py (rev 0)
+++ trunk/pyx/examples/graphs/function.py 2006-05-21 15:16:32 UTC (rev 2745)
@@ -0,0 +1,6 @@
+from pyx import *
+g = graph.graphxy(width=8)
+g.plot(graph.data.function("y(x)=sin(x)/x", min=-15, max=15))
--- trunk/pyx/examples/graphs/function.txt (rev 0)
+++ trunk/pyx/examples/graphs/function.txt 2006-05-21 15:16:32 UTC (rev 2745)
@@ -0,0 +1,32 @@
+Plotting a mathematical function
+Here, we explain how to plot the graph of a real-valued mathematical function of
+a single real parameter. ...
+As in the previous example, we first create a `graph.graphxy` instance passing
+the width as argument. We then pass a `graph.data.function` instance to the
+`plot` method of the graph. As first argument, we pass the function in the form
+"y(x) = f(x)". Here, the left-hand side of the equation defines which parameter
+is independent (here: `x`) and which one is dependent (here: `y`). We also need
+to inform PyX about the range of the independent variable. This is done by passing
+the parameters `min` and `max`.
+! In order to increase the resolution of the function graph, you can use the
+parameter `points` of the `graph.data.function` class to increase the number of
+sampling points from its default value of `100`.
+Note that the default graph style for function data is `graph.style.line` synce
+PyX assumes a continuous x-range.
+! You only need to pass the `min` and `max` parameters to the
+`graph.data.function` class, if PyX cannot figure out an axis range by itself.
+Thus, an alternative way to achieve the above result would look like
+ g = graph.graphxy(width=8, x=graph.axis.linear(min=-15, max=15))
+Here, we explicitely define an x-axis range by passing an appropriate
+argument to the `x` parameter of the `graph.graphxy` class.
+! For PyX it does not matter, whether you plot a function of a parameter `x` or
+a parameter `y`. Thus, you may as well write
+ g.plot(graph.data.function("x(y)=sin(y)/y", min=-15, max=15))
+to obtain a plot where the y-coordinate is the independent one.
--- trunk/pyx/examples/graphs/lissajous.txt 2006-05-20 15:46:35 UTC (rev 2744)
+++ trunk/pyx/examples/graphs/lissajous.txt 2006-05-21 15:16:32 UTC (rev 2745)
@@ -5,7 +5,7 @@
argument, a minimal and a maximal value given as the second and third argument
and an expression string as forth argument. ... This expression string assigns a
tuple of expressions to a tuple of data names. As usual the styles will decide
-#what those data names are responsible for.
+what those data names are responsible for.
! Like for the function, you can also access external data and functions in your
expression. Suppose we want to provide the data for this example by means of
--- trunk/pyx/examples/graphs/minimal.py 2006-05-20 15:46:35 UTC (rev 2744)
+++ trunk/pyx/examples/graphs/minimal.py 2006-05-21 15:16:32 UTC (rev 2745)
@@ -4,14 +4,3 @@
g.plot(graph.data.file("minimal.dat", x=1, y=2))
-# the file minimal.dat looks like:
-# 1 2
-# 2 3
-# 3 8
-# 4 13
-# 5 18
-# 6 21
-# graph styles can be modified by a second parameter to the plot method:
-# g.plot(graph.data.file("minimal.dat", x=1, y=2), [graph.style.line()])
--- trunk/pyx/examples/graphs/minimal.txt 2006-05-20 15:46:35 UTC (rev 2744)
+++ trunk/pyx/examples/graphs/minimal.txt 2006-05-21 15:16:32 UTC (rev 2745)
@@ -1,6 +1,15 @@
-Basic graph drawing: data contained in a file
+Plotting data contained in a file
This example shows how to draw a graph representing data stored in a file. ...
+We assume that the data is arranged in the file `minimal.dat` in a whitespace-separated
+ # minimal.dat
+ 1 2
+ 2 3
+ 3 8
+ 4 13
+ 5 18
+ 6 21
The first step is to create an instance of the `graphxy` class which can be
found in the `graph` module. By convention, we call it `g`. The constructor
@@ -18,10 +27,33 @@
column of the file contains the x (y) values. The `graph.data.file` instance is
then directly passed to the `plot` method of the graph `g`.
+! Note that PyX by default ignores comments starting by a # sign when reading
+in the data from the file.
+!! The previous statement is actually not completely correct, as PyX
+uses the last comment preceding the actual data to give names to the columns.
+Thus, for a file looking like
+ # my data (this line is ignored by PyX, but not the following)
+ # x y
+ 1 2
+you wouldn't need to label the columns in the `graph.data.file` call at all.
Finally, we write the graph to an EPS and PDF file. Here, we use that every
graph is (by inheritance) an instance of the `canvas` class, as well, such that
we can directly write it into a file.
! Of course, you can also insert a graph into another canvas and write this
canvas later to a file. This way, you can, for instance, easily arrange more
-than one graph on a page.
+than one graph on a page. Later examples will make use of this fact.
+In PyX, the way data is plotted in a graph is defined by a so-called graph
+style. A couple of standard graph styles are contained in the module
+`graph.style`. Depending on the data source, PyX chooses a default style. Here,
+we are taking the data from a file and PyX assumes that the values represent a
+discrete set of data points. Hence, it chooses the symbol style
+`graph.style.symbol` to plot the data. To override this default behaviour, you
+can pass a list of styles as second argument to the `plot` method. For instance,
+to have PyX drawing a line through the data points, you can use
+ g.plot(graph.data.file("minimal.dat", x=1, y=2), [graph.style.line()])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.