{"id":40,"date":"2008-02-27T02:16:42","date_gmt":"2008-02-27T00:16:42","guid":{"rendered":"http:\/\/142.93.241.207\/?p=40"},"modified":"2008-02-27T02:18:25","modified_gmt":"2008-02-27T00:18:25","slug":"contours-plots-with-gnuplot","status":"publish","type":"post","link":"https:\/\/www.albertopassalacqua.com\/?p=40","title":{"rendered":"Contours plots with gnuplot"},"content":{"rendered":"<p>Working in CFD, I often have to create contours plots starting from rough data in a text file generated by in house codes. This can be easily accomplished using <a href=\"http:\/\/www.gnuplot.info\/\" target=\"_blank\">gnuplot<\/a>. Here you can see a simple example of what you can do.<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.albertopassalacqua.com\/wp-content\/uploads\/Images\/Plot.jpg\" alt=\"Contour plot generated by gnuplot with the settings shown below\" title=\"Contour plot generated by gnuplot with the settings shown below\" style=\"width: 423px; height: 373px\" height=\"373\" width=\"423\" \/><\/p>\n<p>Being an openSUSE user, I will explain how to install gnuplot on this distribution, but the instructions to generate contours plots are absolutely general.<\/p>\n<ul>\n<li>The installation of gnuplot on openSUSE 10.3 is straightforward. Just use the 1-click install link available <a href=\"http:\/\/software.opensuse.org\/ymp\/openSUSE%3A10.3\/standard\/gnuplot.ymp\" target=\"_blank\">here<\/a>, and follow the procedure shown by the installer.<\/li>\n<li>Gnuplot requires the data to be saved in a text file organized in one of the two following ways:\n<ul>\n<li>One set of 3 coordinates (x y z) per line, with line breaks separating the data, and an empty line to separate the rows of the matrix of data.<\/li>\n<li>One  single value (z) per line, with line breaks separating data, and an empty line to separate the rows of the matrix of data. For example, if you have a 3&#215;2 matrix of data, the corresponding file will be:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<blockquote>\n<blockquote><p>a11<\/p>\n<p>a12<\/p>\n<p>&#8212;- empty line &#8212;-<\/p>\n<p>a21<\/p>\n<p>a22<\/p>\n<p>&#8212;- empty line &#8212;-<\/p>\n<p>a31<\/p>\n<p>a32<\/p><\/blockquote>\n<\/blockquote>\n<ul>\n<li>Once the data to plot are prepared in that format, which can be easily implemented in all computational codes, just start gnuplot in a terminal, typing <em>gnuplot.<\/em><\/li>\n<li> The instruction to plot a simple contour plot are the following, assuming the data file is called data.dat:\n<ul>\n<li><strong>set size square<\/strong> -&gt; It sets that the plot must be squared. Of course this is optional, and depends on the case.<\/li>\n<li><strong>unset title<\/strong> -&gt; It removes the title. You can use <strong>set title &#8216;text&#8217;<\/strong> to set an appropriate title if you want.<\/li>\n<li><strong>set pm3d map<\/strong> -&gt; It configures gnuplot to generate contour plots.<\/li>\n<li><strong>set xrange [0:100]<\/strong> and <strong>set yrange [0:100]<\/strong> -&gt; They set the range of the plot. Change the interval according to your data.<\/li>\n<li><strong>set format x &#8220;&#8221;<\/strong> and <strong>set format y &#8220;&#8221;<\/strong> -&gt; They remove the numbers from the axes.<\/li>\n<li><strong>set cbrange [0:1]<\/strong> -&gt; It sets the range of the colorbar in the contour plot. Values out of range are coloured as the closest extreme value.<\/li>\n<li><strong>set palette rgbformulae 22,13,10<\/strong> -&gt; It sets the colour palette. Please, see the reference for further information on this.<\/li>\n<li><strong>splot &#8216;data.dat&#8217;<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li>At this point, gnuplot is set properly to plot your data. Just check the plot by showing it with: <strong>splot &#8216;data.dat&#8217;<\/strong><\/li>\n<li>If the result is satisfactory, you can easily export it to an eps file, with the following commands:\n<ul>\n<li><strong>set term postscript enhanced color<\/strong><\/li>\n<li><strong>set output &#8220;data.eps&#8221;<\/strong><\/li>\n<li><strong>replot<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Gnuplot offers a lot more features than those discussed here in short. Please refer to its <a href=\"http:\/\/www.gnuplot.info\/documentation.html\" target=\"_blank\">documentation<\/a> for further information. A useful guide which helped me to write this post can be found <a href=\"http:\/\/t16web.lanl.gov\/Kawano\/gnuplot\/index-e.html\" target=\"_blank\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working in CFD, I often have to create contours plots starting from rough data in a text file generated by in house codes. This can be easily accomplished using gnuplot. Here you can see a simple example of what you can do. Being an openSUSE user, I will explain how to install gnuplot on this distribution, but the instructions to generate contours plots are absolutely general. The installation of gnuplot on openSUSE 10.3 is straightforward. Just use the 1-click install link available here, and follow the procedure shown by the installer. Gnuplot requires the data to be saved in a text file organized in one of the two following ways: One set of 3 coordinates (x y z) per line, with line breaks separating the data, and an empty line to separate the rows of the matrix of data. One single value (z) per line, with line breaks separating data, and an empty line to separate the rows of the matrix of data. For example, if you have a 3&#215;2 matrix of data, the corresponding file will be: a11 a12 &#8212;- empty line &#8212;- a21 a22 &#8212;- empty line &#8212;- a31 a32 Once the data to plot are prepared in that format, which can be easily implemented in all computational codes, just start gnuplot in a terminal, typing gnuplot. The instruction to plot a simple contour plot are the following, assuming the data file is called data.dat: set size square -&gt; It sets that the plot must be squared. Of course this is optional, and depends on the case. unset title -&gt; It removes the title. You can use set title &#8216;text&#8217; to set an appropriate title if you want. set pm3d map -&gt; It configures gnuplot to generate contour plots. set xrange [0:100] and set yrange [0:100] -&gt; They set the range of the plot. Change the interval according to your data. set format x &#8220;&#8221; and set format y &#8220;&#8221; -&gt; They remove the numbers from the axes. set cbrange [0:1] -&gt; It sets the range of the colorbar in the contour plot. Values out of range are coloured as the closest extreme value. set palette rgbformulae 22,13,10 -&gt; It sets the colour palette. Please, see the reference for further information on this. splot &#8216;data.dat&#8217; At this point, gnuplot is set properly to plot your data. Just check the plot by showing it with: splot &#8216;data.dat&#8217; If the result is satisfactory, you can easily export it to an eps file, with the following commands: set term postscript enhanced color set output &#8220;data.eps&#8221; replot Gnuplot offers a lot more features than those discussed here in short. Please refer to its documentation for further information. A useful guide which helped me to write this post can be found here.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[116,22,21,114],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-cfd","tag-cfd","tag-contours-plot","tag-gnuplot","tag-opensuse"],"_links":{"self":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":1,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":580,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions\/580"}],"wp:attachment":[{"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopassalacqua.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}