You are here: home python plotsvg

The python module plotsvg: Documentation and User Guide

Download plotsvg

plotsvg.py is a python module. It is a standard text file, not an executable, and it can therefore be downloaded on any platform on which python is installed (see here for instructions how to install python). Because the server does not allow to download files with .py extension, all xxx.py files on this website are presented as xxx.txt files that you can download. The plotsvg.txt files are extended with a prefixed date (format yymmdd) in order to distinguish versions. After downloading please change the extension back into .py and remove the date prefix before installing the file into your python system.

Install the plotsvg.py file in a place where your python program can find it: preferably in the folder Lib/site-packages/ in your python distribution. You can also install it in a folder like 'mymodules' in your workdirectory when you have extended the python path to include this folder.


download 141210plotsvg.txt


How to save SVG pictures as png or jpg files

The python module plotsvg contains the class Figure() which produces a fig.svg file that can be rendered by svg-enabled browsers. SVG stands for "scalable vector graphics", a W3C standard for describing vector graphics elements. Most modern browsers like Firefox, Opera, Safari, Google Chrome are svg-enabled. Until recently, the support by Microsoft's Internet Explorer has been fragmentary. SVG graphs can easily be transformed into .png or .jpg raster images by processing a screen dump ('PrintScrn') with a graphics utility as Paint (for Windows) or the GNU Image Manipulation Program Gimp. For higher resolution than your screen size there are conversion tools on internet.

Defined colors (show colortest.svg in a separate window)

(string of 3 hexadecimal numbers):
Black, White, Yellow, Darkgrey, Red, Brown, Green, Blue, Violet, Lightgrey, Lightred, Lightorange, Lightyellow, Lightgreen, Lightblue, Lightviolet

Available fonts

The availability of fonts depends on the browser and the operating system. For compatibility with postscript fonts, it is advised to use only one of the following font families:

Arial, Helvetica, sans-serif
Times New Roman, Times, serif
Courier New, Courier, monospace

These fonts include the greek and mathematical symbols that are defined in the postscript standard font "symbol". See showfonts.html for a complete set of characters.

We recommend the font-style attributes: normal (default) or italic and the font-weight attributes normal (default) or bold.

The class "Figure()"

An instance of the Figure class is created by typing f=Figure() (after importing all of plotsvg). Now f is defined as a Figure instance. Attributes and methods of f are then available as f.attribute or f.method(arguments).

Usually a figure f=Fig()is first defined as an instant of the Figure() claas, after which the method f.frame() constructs a coordinate frame with optional title and labels. All default attributes can be user-modified. Then data are plotted as a series of symbols with optional error bars and connecting lines or curves by the methods f.plotp(), f.plotc(), f.plotf(). At any stage the figure can be viewed by the command f.show() which will produce and show a file fig.svg.

Figure attributes and their default values

The actual values of all attributes can be viewed at any time by the python command f.attr(). An attribute value can be changed by a python assignment, e.g. f.size=[5500,6400] will change the default size of [5500,4400] to [5500,6400]. This should be executed before the attribute is used, i.e. in this case before the method frame() is applied.

Figure methods

The Figure class has several methods (for details type help(plotsvg.Figure.xxx) where xxx=method):

addobject(position,obj[,options] Inserts svg object at given position
addtext(position, textline[,options]) Inserts line of text at given position
attributes() or attr() Prints the present values of attributes.
frame(xyrange[, options]) Defines coordinate frame with scales.
parse(s[,options]) Parses text (internal use only)
plotc(data[,options]) Plots cumulative distribution of data
plotf(function[,options]) Plots a function
plotm(M[,options]) Plots a matrix with interpolated colors
plotp(data[,options]) Plots a set of points, optional with lines and error bars
line(start,end[,options]) Draws line from start to end
show([options]) Displays result and writes the svg to a file

The module plotsvg.py defines several functions (for details type help(plotsvg.xxx) where xxx=function):

autoplotc(data[,options]) plots cumulative distribution automatically
autoplotf(function,xrange[,options]) plots a function automatically
autoplotm (M[,options]) plots a color matrix automatically
autoplotp(data[,options]) plots data points automatically
cinterpol(x,data[,options]) gives cubic interpolation of data
fminmax(function,xrange) gives min and max value of function in xrange
spline(data[,options]) cubic spline generation

Documentation

This page contains online documentation for plotsvg. The module itself contains up-to-date documentation that can be invoked (after from plotsvg import *) by the command help:

>>>import plotsvg
>>>from plotsvg import *
>>>help(plotsvg)
>>>help(autoplotp)
>>>help(Figure.plotp)

The last 3 lines produce documentation respectively, on the module as a whole, a function in the module, a Figure method.

A complete downloadable manual in pdf format is presently in preparation.