gnuplots in svg
Gnuplot supports outputting svgs (I use gnuplot 4.6 patchlevel 3). See, for example, the plot above (which is a nice projection of the world centered at Rotterdam). By clicking on the plot, the x-y position of the mouse pointer is indicated in the plot (in this case the x-y distance in meters of any point on earth to Rotterdam).
The gnuplot-commands to produce an svg are:
set term svg size 300,200 # or your size
set output "x.svg"
plot x # or your fancy plot
unset output
This will produce:
To get the mouse pointer location plotted in the plot add "mouse" when setting the term:
set term svg mouse size 300,200 # or your size
This will produce:
To be able post such an svg on a website, you must add the necessary
javascript file gnuplot_svg.js
" and change the svg to be able
to find this file.
- Look in the svg file for the path and the name of the file. For me this was:
xlink:href="/home/obooij/linux/share/gnuplot/5.0/js/gnuplot_svg.js"
- Copy this file to the pc or server on which you have your webpage.
- Change the reference to in the svg to this file:
xlink:href="./gnuplot_svg.js"
As can be seen an unnecessary border is added to the plot. To remove this edit the produced svg and change the 17th line from:
<rect x="0" y="0" width="300" height="200" fill="#ffffff" stroke="black" stroke-width="1"
to
<rect x="0" y="0" width="300" height="200" fill="#ffffff" stroke="black" stroke-width="0"
This will produce:
BTW, if the unset output
command is not given, then the
final </svg>-tag will not be written to the file causing
viewers to complain. For example google-chrome says:
error on line 124 at column 21: Extra content at the end of the
document
BTW-2, gnuplot does not seem to support replot
for svg
terms. With google-chrome I get:
error on line 227 at column 5: Opening and ending tag mismatch: svg
line 0 and g
Another way to generate plots for the web using gnuplot is its canvas terminal. I did not check it out yet.
Related to gnuplot+web I found this site, which makes gnuplot interactive. (I should start using clang...)