Gnuplot: SVG export and Inkscape — annoyances and workarounds

I’m making some data plots with gnuplot right now that will be fed to pdfLaTeX later. So I could just have gnuplot create .ps or .eps files, but for some reason it always gets the font completely wrong. When reverse engineering pdf files that have the font I want and feeding gnuplot with that exact font name, the postscript console crashes fatally. Bummer.

So I tried the SVG console. The fonts are OK and I can just use Inkscape to do all the post processing I want and export to PDF. BINGO – but that was too easy, Murphy’s Law is lurking somewhere.

To avoid having to type all of this again and again, you can just put it into a text file and call gnuplot like this:

The path to the data file to be plotted is relative to the current working directory. So this creates an SVG file, Inkscape loads it just fine, but there are quite a few annoyances:

  • data point marker (dots/circles/boxes) are invisible (but there)
  • xy-axes are invisible
  • data point markers get lost when copying to a new SVG document
  • can’t change the stroke width on markers
  • “fit page to selection” doesn’t work – bounding box error ?

It turns out that gnuplot’s SVG terminal uses the term “currentColor”, which seems to confuse Inkscape. This has been filed in the bugtracker before. A quick fix is to replace every single instance of “color: somecolor; stroke: currentColor” with “color: somecolor; stroke: somecolor”. This is not 100% perfect, but as I’m post processing the files with Inkscape anyway, I can change colors later if need be. Here’s a little Perl script that does the job:

It’s used like so: cat data_plot.svg | ./script.pl > ./fixed_data_plog.svg

So now all the axes and data point markers show up, but “fit page to selection” still doesn’t work. Why not just copy the plot to a new SVG document, maybe that takes care of that? But oh no, the data point markers are all gone now ;-( By looking at the SVG file I found that gnuplot tried to be clever. Instead of drawing new data point markers again and again, it _defined_ the object once in the “” section and accessed it by linking to the definition again and again.

It just so happens, that when copying the data plot to a new SVG document, the section is _not_ copied. All the links point to nowhere and the data point markers are lost. Also it was not possible to change the stroke width of these markers. By a little bit of trial and error I found out that by applying the Inkscape command “Edit –> Clone –> Unlink Clone” to all the markers they are turned to individual objects and can now be copied and modified as desired. This took the better of one full working day and has been filed to the bugtracker. I hope this is fixed in the upcoming version 0.47 of Inkscape.

This entry was posted in Software. and tagged , , , , . Bookmark the permalink.