Stephan Schlamminger


Analog Meter in SVG File with python

The motivation for this fun little project was that I wanted to share the state of our experiment with my colleagues. The idea was to put a .svg file in a html file that everybody can see. The state of the experiment is best given by the uncertainty that we assign to its result. The absolute best number the experiment has ever produced has a relative uncertainty of 36x10-9. If the experiment is not running the uncertainty is 100%. Hence the analog display should go from 10-1 to 10-9.

I made the above template of the meter with Inkscape (rightclick to download). I used a spreadsheet to calculate the positions of the divisions. The meter spans 140 degrees and 9 decades. One decade is a bit more than 15.5 degrees. In each decade thinner lines mark the positions 2,5, and 8. Finally the purple indicator was added in Inkscape. By right clicking on the indicator, an ID can be assigned to this object, here appropriately "Indicator".

The python script, shown below, parses the svg file using the minidom module (svg is a xml file). The program iterates over all attributes "id" until it finds "Indicator". Once the indicator is found the prorgam will replace the coordinates of the indicator to reflect the value that one wants to display. A new file w.svg will be written to disk. This file will be displayed in a html file.

Here is the source code of the python code that takes the new value as a command line argument:

Have fun playing with the code and the meter.