{"id":169,"date":"2013-09-05T21:33:34","date_gmt":"2013-09-05T21:33:34","guid":{"rendered":"http:\/\/www.realfogman.de\/?page_id=169"},"modified":"2013-10-24T19:27:02","modified_gmt":"2013-10-24T19:27:02","slug":"plot2gp-producing-gnuplottex-plots-from-octave-matlab","status":"publish","type":"page","link":"https:\/\/www.fogman.de\/?page_id=169","title":{"rendered":"plot2gp &#8211; Producing gnuplot+TeX plots from Octave \/ Matlab"},"content":{"rendered":"<p><a href=\"http:\/\/www.fogman.de\/wp-content\/uploads\/2013\/10\/plot2gp.m\">plot2gp<\/a>\u00a0(24.10.2013)<\/p>\n<p>This page is dedicated to a program which I called\u00a0<strong>plot2gp<\/strong>. Basically it takes an\u00a0<a title=\"Octave\" href=\"http:\/\/www.gnu.org\/software\/octave\/\">Octave<\/a>\u00a0or\u00a0<a title=\"Matlab\" href=\"http:\/\/www.mathworks.com\">Matlab<\/a>\u00a0figure and produces a\u00a0TeX\u00a0(Tikz) plot consisting of\u00a0<a title=\"gnuplot\" href=\"http:\/\/gnuplot.sourceforge.net\/\">gnuplot<\/a>\u00a0commands\u00a0from it, like:<\/p>\n<pre lang=\"java\" line=\"1\">fig = figure(1);\r\nx = 0:0.1:2*pi;\r\nplot( x, sin(x) );\r\ngrid on; hold on;\r\nxlabel('x $\\rightarrow$');\r\nylabel('sin(x) $\\rightarrow$');\r\nlegend('sin(x)');\r\nplot2gp( 'test.tex', fig );<\/pre>\n<p>The output &#8220;<em>test.tex<\/em>&#8221; can then be used in LaTeX like this:<\/p>\n<pre lang=\"latex\" line=\"1\">\\documentclass[10pt]{article}\r\n\\usepackage[T1]{fontenc}\r\n\\usepackage{textcomp}\r\n\\usepackage[english]{babel}\r\n\\usepackage{blindtext}\r\n\r\n\\usepackage[utf8x]{inputenc}\r\n\\usepackage{gnuplottex}\r\n\\usepackage{gnuplot-lua-tikz}\r\n\r\n\\begin{document}\r\n\r\n\\begin{figure}[h]\r\n  \\centering\r\n  \\input{test.tex}\r\n  \\caption{This is a test plot in Octave\/Matlab.}\r\n\\end{figure}\r\n\r\n\\end{document}<\/pre>\n<p>The result looks like this:<\/p>\n<p><a href=\"http:\/\/www.fogman.de\/wp-content\/uploads\/2013\/09\/plot_test.pdf\">plot_test<\/a><\/p>\n<p><em>Why didn&#8217;t\u00a0i\u00a0use\u00a0<a title=\"matlab2tikz\" href=\"https:\/\/github.com\/nschloe\/matlab2tikz\">matlab2tikz<\/a>\u00a0and\u00a0<a href=\"http:\/\/pgfplots.sourceforge.net\/\">pgfplots<\/a>\u00a0?:<\/em><\/p>\n<p>For sure,\u00a0i\u00a0did use both in order to produce (really) good looking graphs for scientific publications! And I still strongly recommend these two programs in combination with LaTeX etc. But I had a little problem, which I couldn&#8217;t solve with\u00a0pgfplots: Until now,\u00a0pgfplots\u00a0is missing\u00a0a decent\u00a0zBuffer\u00a0algorithm, which I needed for a few pictures. Basically, I needed to plot two (or more) surf plots in one plot. There\u00a0exists\u00a0certain solutions in the net, but they all involve to much user\u00a0interacton\u00a0(doing the\u00a0zBuffering\u00a0by\u00a0hant\u00a0etc.). So I decided to\u00a0do\u00a0these plots with\u00a0gnuplot. And luckily, there is a\u00a0<a title=\"gnuplot and tikz\" href=\"http:\/\/www.timteatro.net\/2010\/07\/18\/gnuplottikz-for-stunning-latex-plots\/\">way<\/a>\u00a0to\u00a0<a title=\"another gnuplot + tikz example\" href=\"http:\/\/www.texample.net\/tikz\/examples\/gnuplot-basics\/#c931\">include<\/a>\u00a0gnuplot\u00a0plots easily into LaTeX.<\/p>\n<p><em>Update 24.10.2013:<\/em><\/p>\n<p><strong>Download here:<\/strong>\u00a0<a href=\"http:\/\/www.fogman.de\/wp-content\/uploads\/2013\/10\/plot2gp.m\">plot2gp<\/a><\/p>\n<ul>\n<li>Added histogram plots.<\/li>\n<li>Some minor big fixes.<\/li>\n<\/ul>\n<p><em>Initial version:<\/em><\/p>\n<p><strong>Download here:<\/strong>\u00a0<a href=\"http:\/\/www.fogman.de\/wp-content\/uploads\/2013\/09\/plot2gp.m\">plot2gp<\/a><a href=\"http:\/\/www.fogman.de\/wp-content\/uploads\/2013\/09\/plot2gp.m\"><br \/>\n<\/a><\/p>\n<p>The initial version, does not contain any\/much help information. It works for many different plot types but there are still many things missing like:<\/p>\n<ul>\n<li>3d plots have a fixed view. Rotation of a 3d plot in Octave\/Matlab will not change the view in the\u00a0gnuplot\u00a0output. Although, the &#8220;<em>set view &#8230;&#8221;<\/em>\u00a0command can easily be altered in the output.<\/li>\n<li>No text plots.<\/li>\n<\/ul>\n<p>Some functionality which I&#8217;ve\u00a0added and might help:<\/p>\n<ul>\n<li>There exists the possibility to define user specific options.<\/li>\n<\/ul>\n<p>Here is a little document, which provides some more basic examples:<\/p>\n<p><a href=\"http:\/\/www.fogman.de\/wp-content\/uploads\/2013\/09\/figure.pdf\"><\/a><a href=\"http:\/\/www.fogman.de\/wp-content\/uploads\/2013\/10\/figure.pdf\">Basic Examples<\/a><\/p>\n<p>Please, feel free to contact me if you have some improvements \/ advices \/ or comments.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>plot2gp\u00a0(24.10.2013) This page is dedicated to a program which I called\u00a0plot2gp. Basically it takes an\u00a0Octave\u00a0or\u00a0Matlab\u00a0figure and produces a\u00a0TeX\u00a0(Tikz) plot consisting of\u00a0gnuplot\u00a0commands\u00a0from it, like: fig = figure(1); x = 0:0.1:2*pi; plot( x, sin(x) ); grid on; hold on; xlabel(&#8216;x $\\rightarrow$&#8217;); ylabel(&#8216;sin(x) &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.fogman.de\/?page_id=169\"> <span class=\"screen-reader-text\">plot2gp &#8211; Producing gnuplot+TeX plots from Octave \/ Matlab<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-169","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.fogman.de\/index.php?rest_route=\/wp\/v2\/pages\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fogman.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.fogman.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.fogman.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fogman.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=169"}],"version-history":[{"count":38,"href":"https:\/\/www.fogman.de\/index.php?rest_route=\/wp\/v2\/pages\/169\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/www.fogman.de\/index.php?rest_route=\/wp\/v2\/pages\/169\/revisions\/252"}],"up":[{"embeddable":true,"href":"https:\/\/www.fogman.de\/index.php?rest_route=\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/www.fogman.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}