<?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>hidden3d &#8211; Gnuplotting</title>
	<atom:link href="./index.html?simply_static_page=1921" rel="self" type="application/rss+xml" />
	<link>./../../../index.html</link>
	<description>Create scientific plots using gnuplot</description>
	<lastBuildDate>Mon, 02 Jan 2023 18:38:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
	<item>
		<title>Plotting cubes</title>
		<link>./../../../plotting-cubes/index.html</link>
					<comments>./../../../plotting-cubes/index.html#comments</comments>
		
		<dc:creator><![CDATA[hagen]]></dc:creator>
		<pubDate>Thu, 22 Aug 2013 09:27:23 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cube]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[hidden3d]]></category>
		<category><![CDATA[implicit]]></category>
		<category><![CDATA[pm3d]]></category>
		<category><![CDATA[splot]]></category>
		<category><![CDATA[sprintf]]></category>
		<category><![CDATA[stats]]></category>
		<guid isPermaLink="false">./../../../index.html?p=1809</guid>

					<description><![CDATA[On the PGF plots page I found a nice example of visualizing data with cubes. Here we will recreate the same with gnuplot as you can see in Fig. 1. Fig. 1 Cubes with different colors. (code to produce this figure, cube function, data) We need basically two things in order to achieve it. First [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>On the <a href="http://pgfplots.sourceforge.net/">PGF plots page</a> I found a nice example of visualizing data with cubes. Here we will recreate the same with gnuplot as you can see in Fig. 1.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/cube.png" alt="Cubes"/></p>
<p class="caption">
        <strong>Fig. 1 </strong> Cubes with different colors. (<a href="./../../../code/cube.gnu" type="text/plain" rel="nofollow">code to produce this figure</a>, <a href="./../../../code/cube.fct" rel="nofollow">cube function</a>, <a href="./../../../data/cube_positions.txt" rel="nofollow">data</a>)
    </p>
</div>
<p>We need basically two things in order to achieve it. First we have to plot a single cube with gnuplot. This is not as straight forward as you may think. We have to define a data file for it and plot it with the <code>pm3d</code> style which will result in Fig. 2.</p>
<pre>
# single cube
0 0 0
0 0 1
0 1 1
0 1 0
0 0 0

1 0 0
1 0 1
1 1 1
1 1 0
1 0 0

0 0 0
1 0 0
1 1 0
0 1 0
0 0 0

0 0 1
1 0 1
1 1 1
0 1 1
0 0 1
</pre>
<pre class="prettyprint">
set cbrange [0.9:1]
set palette defined (1 '#ce4c7d')
set style line 1 lc rgb '#b90046' lt 1 lw 0.5
set pm3d depthorder hidden3d
set pm3d implicit
unset hidden3d
splot 'cube.txt' u 1:2:3:(1) w l ls 1
</pre>
<p>The use of the fourth <code>(1)</code> column for the <code>splot</code> command ensures that the cube gets the same color on every side. Only the edges are highlighted by a slighty different color given by the line style.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/single_cube.png" alt="A single cube"/></p>
<p class="caption">
        <strong>Fig. 2 </strong>A single cube. (<a href="./../../../code/single_cube.gnu" type="text/plain" rel="nofollow">code to produce this figure</a>, <a href="./../../../data/cube.txt" rel="nofollow">data</a>)
    </p>
</div>
<p>In a second step we reuse the code from the <a href="./../../../object-placement-using-a-data-file/index.html">Object placement using a data file</a> entry in order to plot cubes at different positions with different colors. To get the different colors and positions we replace the cube.txt file with a <a href="./../../../code/cube.fct">cube function</a> that returns the values for the desired position and color.</p>
<pre class="prettyprint">
add_cube(x,y,z,c) = sprintf('cube(%f,%f,%f,%i) w l ls %i,',x,y,z,c,c)
CMD = ''
stats 'cube_positions.txt' u 1:(CMD = CMD.add_cube($1,$2,$3,$4)) nooutput
CMD = 'splot '.CMD.'1/0 w l ls 2'
eval(CMD)
</pre>
]]></content:encoded>
					
					<wfw:commentRss>./../../../plotting-cubes/feed/index.html</wfw:commentRss>
			<slash:comments>30</slash:comments>
		
		
			</item>
		<item>
		<title>Plotting the world revisited</title>
		<link>./../../../plotting-the-world-revisited/index.html</link>
					<comments>./../../../plotting-the-world-revisited/index.html#comments</comments>
		
		<dc:creator><![CDATA[hagen]]></dc:creator>
		<pubDate>Tue, 18 Dec 2012 18:24:07 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[4.6]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[hidden3d]]></category>
		<category><![CDATA[linestyle]]></category>
		<category><![CDATA[linetype]]></category>
		<category><![CDATA[parametric]]></category>
		<guid isPermaLink="false">./../../../index.html?p=1559</guid>

					<description><![CDATA[More than a year ago, we draw a map of the world with gnuplot. But it has been pointed out the low resolution of the map data. For example, Denmark is totally missing in the original data file. The good thing is, there is other data available in the web. In this entry we will [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>More than a year ago, we <a href="./../../../plotting-the-world/index.html">draw a map of the world with gnuplot</a>. But it has been pointed out the low resolution of the map data. For example, Denmark is totally missing in the original <a href="./../../../data/world.dat">data file</a>. The good thing is, there is other data available in the web. In this entry we will consider how to use the physical coastline data from  <a href="http://www.naturalearthdata.com/downloads/">http://www.naturalearthdata.com/downloads/</a> together with gnuplot.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/world3d_revisited.png" alt=""/></p>
<p class="caption">
        <strong>Fig. 1 </strong>Plot of the world with the new data file and a resolution of 1:110m (<a href="./../../../code/world3d_revisited.gnu" type="text/plain">code to produce this figure</a>, <a href="./../../../data/world_110m.txt">data</a>)
    </p>
</div>
<p>At the download page, three different resolutions of the data are available with a scale of 1:10m, 1:50m, or 1:110m. The data itself is stored as <a href="http://en.wikipedia.org/wiki/Shapefile">shape files</a> on naturalearthdata.com. Hence I wrote a <a href="./../../../code/shape2txt/index.html">script</a> that converts the data first to a csv file using the <a href="http://www.gdal.org/ogr2ogr.html">ogr2ogr</a> program. Afterwards the data is shaped with <a href="http://www.gnu.org/software/sed/">sed</a> into the form of the original <a href="./../../../data/world.dat">world.dat</a> file.<br />
Here are the resulting files:</p>
<ul>
<li>1:10m: <a href="./../../../data/world_10m.txt">world_10m.txt</a></li>
<li>1:50m: <a href="./../../../data/world_50m.txt">world_50m.txt</a></li>
<li>1:110m: <a href="./../../../data/world_110m.txt">world_110m.txt</a></li>
</ul>
<p>Fig.1 shows the result for a resolution of 1:110m. Note that we have to use linetype instead of linestyle in gnuplot 4.6 in order to set the colors of the grid and coast line.</p>
<p>In order to compare the different resolutions of the coast line files, we plot only the part of the map where Denmark is located (which is completely missing in the <a href="./../../../data/world.dat">original data</a>).<br />
Here is the example code for a scale of 1:110m.</p>
<pre class="prettyprint">
set xrange [7.5:13]
set yrange [54.5:58]
plot 'world_110m.txt' with filledcurves ls 1, \
    '' with l ls 2
</pre>
<div class="figure">
    <img decoding="async" src="./../../../figs/denmark_110m.png" alt=""/></p>
<p class="caption">
        <strong>Fig. 2 </strong>A plot of Denmark at a resolution of 1:110m. (<a href="./../../../code/denmark.gnu" type="text/plain">code to produce this figure</a>, <a href="./../../../data/world_110m.txt">data</a>)
    </p>
</div>
<div class="figure">
    <img decoding="async" src="./../../../figs/denmark_50m.png" alt=""/></p>
<p class="caption">
        <strong>Fig. 3 </strong>A plot of Denmark at a resolution of 1:50m. (<a href="./../../../code/denmark.gnu" type="text/plain">code to produce this figure</a>, <a href="./../../../data/world_50m.txt">data</a>)
    </p>
</div>
<div class="figure">
    <img decoding="async" src="./../../../figs/denmark_10m.png" alt=""/></p>
<p class="caption">
        <strong>Fig. 4 </strong>A plot of Denmark at a resolution of 1:10m. (<a href="./../../../code/denmark.gnu" type="text/plain">code to produce this figure</a>, <a href="./../../../data/world_10m.txt">data</a>)
    </p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>./../../../plotting-the-world-revisited/feed/index.html</wfw:commentRss>
			<slash:comments>48</slash:comments>
		
		
			</item>
		<item>
		<title>Heat maps</title>
		<link>./../../../heat-maps/index.html</link>
					<comments>./../../../heat-maps/index.html#comments</comments>
		
		<dc:creator><![CDATA[hagen]]></dc:creator>
		<pubDate>Fri, 29 Jul 2011 21:57:07 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[hidden3d]]></category>
		<category><![CDATA[parametric]]></category>
		<category><![CDATA[pm3d]]></category>
		<category><![CDATA[sphere]]></category>
		<guid isPermaLink="false">./../../../index.html?p=980</guid>

					<description><![CDATA[In one post we have used the parametric plot option to plot the world. Here we want to add some temperature data as a heat map to the world plots. The data show the temperature anomalies of the year 2005 in comparison to the baseline 1951-1980 and is part of the GISTEMP data set. Fig. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In one post we have used the parametric plot option to <a href="./../../../plotting-the-world/index.html">plot the world</a>. Here we want to add some temperature data as a heat map to the world plots. The data show the temperature anomalies of the year 2005 in comparison to the baseline 1951-1980 and is part of the <a href="http://data.giss.nasa.gov/gistemp/" target="_blank">GISTEMP</a> data set.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/heatmap2d.png" alt="Heat map" width="350"/></p>
<p class="caption">
        <strong>Fig. 1 </strong>A 2D heat map of the temperature anomalies in 2005 to the baseline 1951-1980 (<a href="./../../../code/heatmap2d.gnu" type="text/plain">code to produce this figure</a>, <a href="./../../../data/temperature.dat">temperature data</a>, <a href="./../../../data/world.dat">world data</a>)
    </p>
</div>
<p>The first problem you face, if you want to create a heat map, is that the data has to be in a specific format shown in the <a href="http://gnuplot.sourceforge.net/demo/heatmaps.html">Gnuplot example page for heat maps</a>. Therefore we first arrange the data and end up with this <a href="./../../../data/temperature.dat">temperature anomalies file</a>. Unknown data points are given by 9999.0.</p>
<p>In order to plot this data to the 2D world map we have to add a reasonable <code>cbrange</code> and a color <code>palette</code> and the plot command for the map:</p>
<pre class="prettyprint">
<span class="k">set</span> cbrange [<span class="n">-5</span>:<span class="n">10</span>]
<span class="k">set</span> palette defined (<span class="n">0</span> <span class="s">"blue"</span>,<span class="n">17</span> <span class="s">"#00ffff"</span>,<span class="n">33</span> <span class="s">"white"</span>,<span class="n">50</span> <span class="s">"yellow"</span>,\
    <span class="n">66</span> <span class="s">"red"</span>,<span class="n">100</span> <span class="s">"#990000"</span>,<span class="n">101</span> <span class="s">"grey"</span>)
<span class="k">plot</span> <span class="s">'temperature.dat'</span> u <span class="n">2</span>:<span class="n">1</span>:<span class="n">3</span> w image, \
     <span class="s">'world.dat'</span> with lines linestyle <span class="n">1</span>
</pre>
<p>The trick with the wide range from 0 to 101 for the color bar is chosen in order to use <code>grey</code> for the undefined values (9999.0) without seeing the grey color in the color bar. The result is shown in Fig. 1.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/heatmap3d.png" alt="Heat map" width="350"/></p>
<p class="caption">
        <strong>Fig. 2 </strong>A 3D heat map of the temperature anomalies in 2005 to the baseline 1951-1980 (<a href="./../../../code/heatmap3d.gnu" type="text/plain">code to produce this figure</a>, <a href="./../../../data/temperature.dat">temperature data</a>, <a href="./../../../data/world.dat">world data</a>)
    </p>
</div>
<p>The same data can easily be applied to the 3D plot of the world. We have to add <code>front</code> to the <code>hidden3d</code> command in order to make the black world lines visible. In addition the radius must be given explicitly as third column to the plot command for the temperature data.</p>
<pre class="prettyprint">
<span class="k">set</span> hidden3d front
<span class="k">splot</span> <span class="s">'temperature.dat'</span> u <span class="n">2</span>:<span class="n">1</span>:(<span class="n">1</span>):<span class="n">3</span> w pm3d, \
      <span class="c">r</span><span class="o">*</span><span class="f">cos</span>(<span
class="v">v</span>)<span class="o">*</span><span class="f">cos</span>(<span
class="v">u</span>),<span class="c">r</span><span class="o">*</span><span class="f">cos</span>(<span class="v">v</span>)<span class="o">*</span><span class="f">sin</span>(<span class="v">u</span>),<span class="c">r</span><span class="o">*</span><span class="f">sin</span>(<span class="v">v</span>) w l ls <span class="n">2</span>, \
      <span class="s">'world.dat'</span> u <span class="n">1</span>:<span class="n">2</span>:(<span class="n">1</span>) w l ls <span class="n">1</span>
</pre>
<p>The result is shown in Fig. 2.</p>
]]></content:encoded>
					
					<wfw:commentRss>./../../../heat-maps/feed/index.html</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Klein bottle</title>
		<link>./../../../klein-bottle/index.html</link>
					<comments>./../../../klein-bottle/index.html#comments</comments>
		
		<dc:creator><![CDATA[hagen]]></dc:creator>
		<pubDate>Tue, 07 Jun 2011 14:05:04 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[depthorder]]></category>
		<category><![CDATA[hidden3d]]></category>
		<category><![CDATA[parametric]]></category>
		<category><![CDATA[pm3d]]></category>
		<category><![CDATA[splot]]></category>
		<category><![CDATA[transparent]]></category>
		<guid isPermaLink="false">./../../../index.html?p=410</guid>

					<description><![CDATA[A Klein bottle is a non-orientable surface, which has no defined left and right, as stated on Wikipedia. There we can also find a Gnuplot plot of the bottle, which we want to fine-tune a little bit in order to reach the result in Fig. 1. Fig. 1 Klein bottle (code to produce this figure) [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>A <a href="http://en.wikipedia.org/wiki/Klein_bottle">Klein bottle</a> is a non-orientable surface, which has no defined left and right, as stated on Wikipedia. There we can also find a <a href="http://en.wikipedia.org/wiki/File:Klein_bottle.svg">Gnuplot plot of the bottle</a>, which we want to fine-tune a little bit in order to reach the result in Fig. 1.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/klein_bottle.png" alt="Klein bottle" width="350"/></p>
<p class="caption">
        <strong>Fig. 1 </strong>Klein bottle (<a href="./../../../code/klein_bottle.gnu" type="text/plain">code to produce this figure</a>)
    </p>
</div>
<p>In order to reach Fig. 1 we start with the definition of the parametric functions given in Wikipedia and do a simple <code>pm3d</code> plot with them.</p>
<pre class="prettyprint">
<span class="k">set</span> <span class="nb">parametric</span>
<span class="f">x</span>(<span class="v">u</span>,<span class="v">v</span>)<span class="o">=</span> <span class="v">v</span><span class="o">&lt;</span><span class="n">2</span><span class="o">*</span><span class="c">pi</span> <span class="o">?</span> <span class="p">(</span><span class="n">2.5</span><span class="n">-1</span><span class="n">.5</span><span class="o">*</span><span class="f">cos</span><span class="p">(</span><span class="v">v</span><span class="p">))</span><span class="o">*</span><span class="f">cos</span><span class="p">(</span><span class="v">u</span><span class="p">)</span><span class="o"> :</span> \
        <span class="v">v</span><span class="o">&lt;</span><span class="n">3</span><span class="o">*</span><span class="c">pi</span> <span class="o">?</span> <span class="n">-2</span><span class="o">+</span><span class="p">(</span><span class="n">2</span><span class="o">+</span><span class="f">cos</span><span class="p">(</span><span class="v">u</span><span class="p">))</span><span class="o">*</span><span class="f">cos</span><span class="p">(</span><span class="v">v</span><span class="p">)</span><span class="o">    :</span> \
                 <span class="n">-2</span><span class="o">+</span><span class="n">2</span><span class="o">*</span><span class="f">cos</span><span class="p">(</span><span class="v">v</span><span class="p">)</span><span class="o">-</span><span class="f">cos</span><span class="p">(</span><span class="v">u</span><span class="p">)</span>
<span class="f">y</span>(<span class="v">u</span>,<span class="v">v</span>)<span class="o">=</span> <span class="v">v</span><span class="o">&lt;</span><span class="n">2</span><span class="o">*</span><span class="c">pi</span> <span class="o">?</span> <span class="p">(</span><span class="n">2.5</span><span class="n">-1</span><span class="n">.5</span><span class="o">*</span><span class="f">cos</span><span class="p">(</span><span class="v">v</span><span class="p">))</span><span class="o">*</span><span class="f">sin</span><span class="p">(</span><span class="v">u</span><span class="p">)</span><span class="o"> :</span> \
                <span class="f">sin</span><span class="p">(</span><span class="v">u</span><span class="p">)</span>
<span class="f">z</span>(<span class="v">u</span>,<span class="v">v</span>)<span class="o">=</span> <span class="v">v</span><span class="o">&lt;</span><span class="c">pi</span>   <span class="o">?</span> <span class="n">-2</span><span class="n">.5</span><span class="o">*</span><span class="f">sin</span><span class="p">(</span><span class="v">v</span><span class="p">)</span><span class="o">             :</span> \
        <span class="v">v</span><span class="o">&lt;</span><span class="n">2</span><span class="o">*</span><span class="c">pi</span> <span class="o">?</span> <span class="n">3</span><span class="o">*</span><span class="v">v</span><span class="n">-3</span><span class="o">*</span><span class="c">pi</span><span class="o">                :</span> \
        <span class="v">v</span><span class="o">&lt;</span><span class="n">3</span><span class="o">*</span><span class="c">pi</span> <span class="o">?</span> <span class="p">(</span><span class="n">2</span><span class="o">+</span><span class="f">cos</span><span class="p">(</span><span class="v">u</span><span class="p">))</span><span class="o">*</span><span class="f">sin</span><span class="p">(</span><span class="v">v</span><span class="p">)</span><span class="o">+</span><span class="n">3</span><span class="o">*</span><span class="c">pi</span><span class="o">  :</span> \
                 <span class="n">-3</span><span class="o">*</span><span class="v">v</span><span class="o">+</span><span class="n">12</span><span class="o">*</span><span class="c">pi</span>
<span class="k">splot</span> <span class="f">x</span><span class="p">(</span><span class="v">u</span><span class="o">,</span><span class="v">v</span><span class="p">)</span><span class="o">,</span><span class="f">y</span><span class="p">(</span><span class="v">u</span><span class="o">,</span><span class="v">v</span><span class="p">)</span><span class="o">,-</span><span class="f">z</span><span class="p">(</span><span class="v">u</span><span class="o">,</span><span class="v">v</span><span class="p">)</span> <span class="nb">w</span> <span class="nb">pm3d</span>
</pre>
<p>The result is shown in Fig. 2.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/klein_bottle1.png" alt="Klein bottle" width="350"/></p>
<p class="caption">
        <strong>Fig. 2 </strong>Klein bottle plotted only with pm3d (<a href="./../../../code/klein_bottle1.gnu" type="text/plain">code to produce this figure</a>)
    </p>
</div>
<p>Now we add some lines to the surface and hide parts, which are not visible in 3d.</p>
<pre class="prettyprint">
<span class="k">set</span> <span class="nb">pm3d</span> <span class="nb">depthorder</span> <span class="nb">hidden3d</span> <span class="n">1</span>
<span class="k">set</span> <span class="nb">hidden3d</span>
</pre>
<p>Here the <code>depthorder</code> option takes care of the right positioning of the bottleneck going back into the bottle, which is not correct in Fig. 2. The <code>hidden3d 1</code> option draws lines in the right order for a correctly looking 3d plot using line style 1. The additional <code>set hidden3d</code> command takes care of showing only those lines that are visible in 3d. These options will result in Fig. 3.</p>
<div class="figure">
    <img decoding="async" src="./../../../figs/klein_bottle2.png" alt="Klein bottle" width="350"/></p>
<p class="caption">
        <strong>Fig. 3 </strong>Klein bottle plotted only with pm3d and hidden3d (<a href="./../../../code/klein_bottle2.gnu" type="text/plain">code to produce this figure</a>)
    </p>
</div>
<p>In order to reach at Fig. 1 we just have to set the surface to be transparent, which can be done by the <code>set style fill</code> command.</p>
<pre class="prettyprint">
<span class="k">set</span> <span class="nb">style</span> <span class="nb">fill</span> <span class="nb">transparent</span> <span class="nb">solid</span> <span class="n">0.65</span>
</pre>
]]></content:encoded>
					
					<wfw:commentRss>./../../../klein-bottle/feed/index.html</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
