<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My 2µF &#187; SVG</title>
	<atom:link href="http://blog.spitzenpfeil.org/wordpress/tag/svg/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.spitzenpfeil.org/wordpress</link>
	<description>&#34;Another visitor! Stay a while. Staaaaay, FOREVER!&#34;</description>
	<lastBuildDate>Tue, 07 Sep 2010 09:28:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Gnuplot: SVG export and Inkscape &#8212; annoyances and workarounds</title>
		<link>http://blog.spitzenpfeil.org/wordpress/2009/07/01/gnuplot-svg-export-and-inkscape-annoyances-and-workarounds/</link>
		<comments>http://blog.spitzenpfeil.org/wordpress/2009/07/01/gnuplot-svg-export-and-inkscape-annoyances-and-workarounds/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 13:29:18 +0000</pubDate>
		<dc:creator>robert</dc:creator>
				<category><![CDATA[Software.]]></category>
		<category><![CDATA[gnuplot]]></category>
		<category><![CDATA[inkscape]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[pdfLaTeX]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://blog.spitzenpfeil.org/wordpress/?p=1799</guid>
		<description><![CDATA[I&#8217;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 &#8230; <a href="http://blog.spitzenpfeil.org/wordpress/2009/07/01/gnuplot-svg-export-and-inkscape-annoyances-and-workarounds/">Continue reading <span class="meta-nav">&#8594;</span></a>


 
 
No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m making some data plots with <a href="http://www.gnuplot.info" target=_blank>gnuplot</a> 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.</p>
<p>So I tried the SVG console. The fonts are OK and I can just use <a href="http://www.inkscape.org" target=_blank>Inkscape</a> to do all the post processing I want and export to PDF. BINGO &#8211; but that was too easy, Murphy&#8217;s Law is lurking somewhere.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">set xlabel <span style="color: #FF0000;">&quot;x-axis label&quot;</span> font <span style="color: #FF0000;">&quot;Bitstream Vera Sans, 12&quot;</span>
set ylabel <span style="color: #FF0000;">&quot;y-axis label&quot;</span> font <span style="color: #FF0000;">&quot;Bitstream Vera Sans, 12&quot;</span>
set title <span style="color: #FF0000;">&quot;title for the plot&quot;</span> font <span style="color: #FF0000;">&quot;Bitstream Vera Sans, 12&quot;</span>
<span style="color: #339900;">#  choose the SVG terminal</span>
set terminal svg font <span style="color: #FF0000;">&quot;Bitstream Vera Sans, 12&quot;</span> linewidth <span style="color: #0000dd;">1</span>
<span style="color: #339900;">#  pipe the output to a file</span>
set output <span style="color: #FF0000;">&quot;|cat &gt;./data_plot.svg&quot;</span>
<span style="color: #339900;"># position of the legend</span>
set key <span style="color: #0000dd;">95</span>,<span style="color:#800080;">0.5</span>
set logscale y
set yrange <span style="color: #008000;">&#91;</span><span style="color:#800080;">0.007</span><span style="color: #008080;">:</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>
<span style="color: #339900;">#  rescale the xy-data and plot it</span>
plot <span style="color: #FF0000;">&quot;&lt;awk '{print $1, -(200/1000000000)/log($2)*1000000}' ascii_data.raw&quot;</span> title <span style="color: #FF0000;">&quot;plot curve name&quot;</span> lt rgb <span style="color: #FF0000;">&quot;blue&quot;</span> w lp</pre></td></tr></table></div>

<p>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:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">gnuplot .<span style="color: #000040;">/</span>my_plot_commands.<span style="color: #007788;">txt</span></pre></td></tr></table></div>

<p>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:</p>
<ul>
<li>data point marker (dots/circles/boxes) are invisible (but there)</li>
<li>xy-axes are invisible</li>
<li>data point markers get lost when copying to a new SVG document</li>
<li>can&#8217;t change the stroke width on markers</li>
<li>&#8220;fit page to selection&#8221; doesn&#8217;t work &#8211; bounding box error ?</li>
</ul>
<p>It turns out that gnuplot&#8217;s SVG terminal uses the term &#8220;currentColor&#8221;, which seems to confuse Inkscape. This has been filed in the <a href="https://bugs.launchpad.net/inkscape/+bug/196291" target=_blank>bugtracker</a> before. A quick fix is to replace every single instance of &#8220;color: somecolor; stroke: currentColor&#8221; with &#8220;color: somecolor; stroke: somecolor&#8221;. This is not 100% perfect, but as I&#8217;m post processing the files with Inkscape anyway, I can change colors later if need be. Here&#8217;s a little Perl <a href='http://blog.spitzenpfeil.org/wordpress/wp-content/uploads/2009/07/svgfix.pl'>script</a> that does the job:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -T -W</span>
<span style="color: #000066;">print</span> <span style="color: #000000; font-weight: bold;">STDERR</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Don't forget to use CLONE--&gt;UNLINK CLONE on the data points<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #009999;">&lt;STDIN&gt;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$line</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/(color:)(.*)(;\ * stroke:)currentColor/$1$2$3$2/</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">print</span> <span style="color: #0000ff;">$line</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>It&#8217;s used like so: cat data_plot.svg | ./script.pl > ./fixed_data_plog.svg</p>
<p>So now all the axes and data point markers show up, but &#8220;fit page to selection&#8221; still doesn&#8217;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 &#8220;&lt;defs&gt;&#8221; section and accessed it by linking to the definition again and again.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #000080;">&lt;</span>defs<span style="color: #000080;">&gt;</span>
...
<span style="color: #000080;">&lt;</span>path id<span style="color: #000080;">=</span><span style="color: #FF0000;">'gpPt0'</span> style<span style="color: #000080;">=</span><span style="color: #FF0000;">'stroke-width:0.222'</span> d<span style="color: #000080;">=</span><span style="color: #FF0000;">'M-1,0 h2 M0,-1 v2'</span><span style="color: #000040;">/</span><span style="color: #000080;">&gt;</span>
...
<span style="color: #000080;">&lt;</span><span style="color: #000040;">/</span>defs<span style="color: #000080;">&gt;</span>
...
...
<span style="color: #000080;">&lt;</span>use xlink<span style="color: #008080;">:</span>href<span style="color: #000080;">=</span><span style="color: #FF0000;">'#gpPt0'</span> transform<span style="color: #000080;">=</span><span style="color: #FF0000;">'translate(545.0,304.1) scale(4.50)'</span> style<span style="color: #000080;">=</span><span style="color: #FF0000;">'color:rgb(  0,   0, 255)'</span><span style="color: #000040;">/</span><span style="color: #000080;">&gt;</span>
...</pre></td></tr></table></div>

<p>It just so happens, that when copying the data plot to a new SVG document, the &lt;defs&gt; 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 &#8220;Edit &#8211;> Clone &#8211;> Unlink Clone&#8221; 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 <a href="https://bugs.launchpad.net/inkscape/+bug/392192" target=_blank>bugtracker</a>. I hope this is fixed in the upcoming version 0.47 of Inkscape.</p>


<p> </p><p> </p><p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.spitzenpfeil.org/wordpress/2009/07/01/gnuplot-svg-export-and-inkscape-annoyances-and-workarounds/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
