Created
March 11, 2015 18:42
-
-
Save stefanthaler/4bb3cec8079a6217d374 to your computer and use it in GitHub Desktop.
Small script that converts a gnuplot file to svg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env python | |
| """ | |
| converts a gnuplot file to svg. | |
| GnuPlot: http://people.duke.edu/~hpgavin/gnuplot.html | |
| """ | |
| import os, tempfile, sys | |
| from tempfile import NamedTemporaryFile | |
| from subprocess import call | |
| from os import listdir | |
| def convert_gp_to_svg(in_file): | |
| f = NamedTemporaryFile(delete=False) #decorate temporary file with gnuplot commands to write as svg | |
| f.write("set terminal svg size 350,262 fname 'Verdana' fsize 10\n") | |
| f.write("set output '%s.svg'\n" % in_file) | |
| f.write( open(in_file).read() ) | |
| f.close() | |
| call(["gnuplot", f.name]) #run gnuplot to save the plot | |
| os.unlink(f.name) #cleanup | |
| #script start | |
| if len(sys.argv) < 2: | |
| print "Usage: python gp_to_svg.py <yourfile 1.pg> .. <yourfile n.pg>" | |
| print "Output: yourfile.pg.svg" | |
| sys.exit(-1) | |
| #convert all .gp files that were appended | |
| [convert_gp_to_svg(in_file) for in_file in sys.argv[1:] if in_file.endswith(".gp")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment