PyX - Examples

The following examples are part of the PyX release 0.10. For each PyX example the source code and the corresponding output are shown. You can take a guided tour through all examples by the prev and next links on the upper right. All the examples and their descriptions are included in the source distribution of PyX in the examples subdirectory.

Some paragraphs (like the one you're just reading) are marked with a dangerous bend sign. Some people will recognize this classification from the TeXbook by D.E. Knuth and we use it at the PyX example pages for the same purpose. The bend mark parts of the description, which require some experiences with PyX. On the other hand those parts can savely be ignored by PyX beginners.

There are even some paragraphs marked as doubly dangerous. The explanations given in those paragraphs provide some deeper insights of what's really going on, but are not important for the average PyX user.

0.1 KB
10.4 KB
6.9 KB

Hello, world!

hello.png
from pyx import *

c = canvas.canvas()
c.text(0, 0, "Hello, world!")
c.stroke(path.line(0, 0, 2, 0))
c.writeEPSfile("hello")
c.writePDFfile("hello")

Description

As it is good practice to say "Hello, world!" in the first example, let's discuss how to do that in PyX.

At first we import the PyX modules. Most PyX programs will start with a line like that. In order to produce some output we create a canvas instance c. Such an instance provides some useful methods to output some text at a certain position and for directly stroking a path, for which we use a line instance from the path module here. Once this is done, we write an EPS file and a PDF file containing all items inserted into the canvas instance.

Further examples