A Python program to produce SVG graphics. Version 0.20 is new on June 22, 2011. Works with Python 2.4, 2.6 and 3.1.

Last modified Sunday, 28-Dec-2014 16:48:06 CST
[an error occurred while processing this directive]

Why another plotting program?

simpleSVG translates user-friendly Python commands into an SVG graphics file. It produces only SVG graphics, and the Python is adapted to SVG. If you know a bit about SVG, such as from An SVG Primer for Today's Browsers the Python commands will be more easily learned and effectively applied.

SVG is a vector graphics format. 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".

simpleSVG is intended to replace vplot, which produced postscript graphics. Like vplot, simpleSVG is intended to simplify the use of graphics primitives, to make nonstandard plots that are not available in traditional plotting programs.

Some links about SVG

Key features of simpleSVG

  1. SVG attributes such as stroke-width are written as stroke_width when used as a keyword in a argument list. simpleSVG will replace the _ with a - when writing the file.

  2. The SVG editor inkscape (excellent cross-platform free software, highly recommended as a companion to simpleSVG), seems to concatenate style attributes. Instead of stroke="blue", stroke-width="3" we see style="stroke:blue;stroke-width=3". simpleSVG had adopted the latter form, concatenated style strings. That may not have been the cleanest decision for simpleSVG, but that is what was done.

  3. simpleSVG ultimately writes the files in standard SVG coordinates in "pt", with the origin in the top left, the first coordinate increasing to the right and the second coordinate increasing down. These will be called SVG coordinates. Coordinates passed as integers are assumed to be in units of "pt".

  4. Coordinates passed as floats are assumed to be in user coordinates: the conventional x and y with an origin at the user-specified lower-left intersection of the left and bottom margins. Often, the user will specify axes to be drawn at the margins, so the user coordinates are also the familiar Cartesian coordinates of a plot. You may see SVG "user coordinates" defined differently in SVG documentation, here the term refers to the simpleSVG implementation.) When simpleSVG writes to a file, user coordinates are converted to SVG coordinates, according to the linear transformation defined by the user.

  5. Rarely, users need to specify position in SVG coordinates at higher resolution than a "pt". For example, simpleSVG.hires(300.23) is interpreted as an SVG coordinate, while 300.23 is a user coordinate. (In versions of less than 0.20, long integers were used for the hi-res coordinates, but a long integer is not a valid type in Python 3.0).

Installing simpleSVG

Here it is: Installing can be as simple as keeping a copy in the same directory as the Python programs that will import it. Or keep it in a directory accessible by your PYTHONPATH.

Using simpleSVG