% simple demo to show the use of GnuPlotStream:
x=[1 2 3 4 5]; y=[5 3 1 5 -4]; y2=[-5 3 -1 5 -4]; u=[0.2 2 1 0.4 3.4];

% clear all graphs:
gps

% plot line - column vectors needed:
gps("plot",[x' y'],"title 'line 1' linecolor rgb 'blue' with lines");

% pause is needed for gnuplot to initialize, without pause next command would be always incorrect
pause(2)

% plot second line - use replot:
gps("replot",[x' y2' u'],"title 'line $\\psi$' linecolor rgb 'red' linetype 1 with errorbars");

%next plot can be proceeded immediatly:
gps("replot",[x' u'],"title '$\\circ$ and $\\times$' linecolor rgb 'green' with lines");

% autoscale all axis:
gps("set autoscale");

% set x axis range:
gps(["set xrange [" num2str(min(x)-0.5,10) ":" num2str(max(x)+1.8,10) "]"]);

% set format of y values:
gps(["set format y '%." num2str(5) "f'"]);

% graph title with latex markings: 
% outer character marks must be ' ' and for gnuplot must be " "
% latex commands must be double \\
gps(['set title "$\\sigma \\Sigma \\aleph^2_{a} \Pi_{\\rm \\Delta}$ 5$\\times$"']);

% set x label:
gps("set xlabel '$\\oint_{0}^{\\infty}x^2$ '");

% set y label:
gps("set ylabel '${{{{y^1_5}^2_4}^3_3}^4_2}^5_1$ '");

filename="gpstest";

% postscript file with set size and fontsize 6:
gps("psp",filename,"linewidth 2 size 14cm,4cm 8");

% convert to pdf:
%ps2epstopdf("gpstest");
%pdftopng("gpstest");

[output, status]=system(['ps2eps -f -l -B ' filename '.ps > /dev/null' ]);
[output, status]=system(['epstopdf ' filename '.eps > /dev/null' ]);

% convert pdf to png:
[output, status]=system(['convert +antialias -density 600x600 ' filename '.pdf ' filename '.png']);

% close plot and remove temporary file:
gps
