I am programming in java and i have to make a plot with some values. The values i want to plot are being written in a file called "cleanOutput.txt" and they are separated by ";". I am writing the following commands on a script file that goes into GnuPlot:
try (PrintWriter writer = new PrintWriter(ficheiroComando)) {
writer.write("set datafile separator \";\"\n");
writer.write("set size ratio 0.75\n");
writer.write("set format x \"%.5f\"\n");
writer.write("set terminal png\n");
writer.write("set output '" + output + "'\n");
writer.write("plot [0:30][0:1]'" + input + "' using 1:2 with lines title 'Suscetiveis' lc rgb 'red',\\\n");
writer.write("'" + input + "' using 1:3 with lines title 'Infetados' lc rgb 'blue',\\\n");
writer.write("'" + input + "' using 1:4 with lines title 'Recuperados' lc rgb 'green'\n");
}
I can use any external library as this is a school project. Here you have some lines of the document input to give you some context:
0,000000;0,500000;0,300000;0,200000;
0,200000;0,501467;0,299024;0,199509;
0,300000;0,502929;0,298052;0,199019;
0,400000;0,504385;0,297084;0,198531;
0,500000;0,505835;0,296121;0,198044;
0,600000;0,507280;0,295162;0,197558;
0,700000;0,508718;0,294207;0,197074;
0,800000;0,510152;0,293257;0,196591;
I want to get a plot where the first column is the x and then each of the following columns will be the y, so that i have 3 plots on the same grid. The thing is, i am having trouble with plotting as i am only getting a horizontal line. Anyone can help?
I have tried messing around with changing the columns i am plotting and have tried different scales on the plot.
As user85421 pointed out in the comments the decimalsign is the problem. Default in gnuplot is typically decimal point .
.
If you type show decimalsign
in the gnuplot console you might get something like this:
decimalsign for input is .
decimalsign for output is .
degree sign for output is °
So, be aware that there is a decimal sign setting for input (input data) and output (numbers in the graph). In gnuplot console type help decimalsign
. It's a bit confusing: set decimalsign ','
will not set your input data decimal sign to ,
.
If you type:
set decimalsign locale "French" # or "German" will also work
set decimalsign "."
and after typing show decimalsign
, you will get:
decimalsign for input is ,
decimalsign for output is .
degree sign for output is °