A vector plotting program written in object-oriented Python. Output is in postscipt. Version 0.93 is new on November 12, 2007.

Last modified Thursday, 27-Dec-2007 23:02:01 CST
[an error occurred while processing this directive]

Warning! vplot has been superseded by simpleSVG.

Why another plotting program?

vplot translates user-friendly Python commands into user-nonhostile postscript. vplot is for those who are not afraid of knowing a bit about postscript.

Some users may find vplot lacking in capabilities and would need to add to the Python code in order to make the plots they need. You will need to know a bit about Python in order to use vplot, even if you do not intend to modify it. Some of my students were first exposed to Python in my course Information Technology Skills for Meteorology. vplot.py is currently a couple hundred lines of object-oriented Python.

vplot may be a good way to learn a little bit about object-oriented programming; it is the way I learned about it. vplot also helps me make plots that I could not make any other way, with what I find in the standard Linux distribution. See the examples at the bottom of this page.

I confess here that when I first heard of the term "vector graphics", I thought it was referring to plots with lots of little arrows. Nope, that is not what it means! Here are some definitions of "vector graphics".

Installing vplot

  1. vplot.py is distributed as a Python module. "Installing" it can be as simple as keeping a copy in the same directory as the Python programs that will import it. Here it is:

  2. You may want import vplot to function from any Python program residing anywhere in your directories. If so, then vplot.py should be placed in a special directory within your home directory for Python modules; mine is simply called python.

    You may want to have a quick look at vplot.py, but you are strongly advised to use an editor that will colorize the Python syntax for you.

  3. If your are running Linux, you may be using the bash shell. If so, then within your .bashrc, put the following two lines:
    export PYTHONPATH  
    After you do that, you may need to type source .bashrc in order for PYTHONPATH to be set properly. See if it is set properly by using the command printenv PYTHONPATH.

Using vplot

  • Now, perhaps in another directory where you can experiment and make a mess, simply type python (or idle). The >>> of the Python interpreter will appear. At those prompts, enter:
    import vplot
    tryit.rect(0., .15, 1., .85) 

    That last command was "Control D", which bumps you out of the Python interpreter. Now, at your shell prompt, type ggv temp.eps to render the postscript code that you made. You may also want to open temp.eps with an editor to see the postscript code.

    The line tryit=vplot.eps_class() instantiated an object in the vplot.eps_class() class. The object you created is named tryit, you are welcome to use any other name. The vplot.eps_class class has certain methods that can be applied to the objects in the class. Above we used the methods for changing colors, drawing a filled circle, an open rectangle, and closing the output file.

    At some point you will need to do some serious inspection of vplot.py to understand how this all works. Note the proliferation of the keyword self, as sort of a placeholder in the argument list of the methods. For example,

      def circle(self,x,y,r,*tags):
        self.eps.write("N %8.2f %8.2f %8.2f csize 0 360 arc %s\n" %
          (self.ix(x), self.jy(y), self.sx(r), detag('CS',tags)))

    This apparently has something to do with how an object name is recognized by the method. But note that circle is actually passed only four arguments, x, y, r, and the optional tag 'F' (to fill with color). vplot is using only some basic methods of object oriented programming, just classes and methods as described in the official tutorial. The chapter Object-Oriented Programming is also useful.

    You may find PostScript Level 2 a useful place to learn about postscript syntax.

    Even the standard Python language uses object-oriented features, which we may use without even thinking of it as being object oriented. In the above snippet of code, self.eps is a file object, which was instantiated when tryit was instantiated (see the vplot.py source). write is a standard method for file objects.

  • Here is an example Python script that makes some slightly more substantive plots: vplotex.py. (Make it executable, type vplotex.py).

vplot examples

Attributes Diagram

Lorenz Equation

Wind rose

Wind rose 2

Wind rose 3