1

I am trying to run the gnuplot to get the graph of all columns in one plot .

I have a output file dump with four columns.

1)Input
2)Ref Output
3)Optimization Output
4)Error between ref and opt output

I am trying to run command with below contents to get one graph but I am getting three graphs instead of one .

I tried by putting same name *.png for all three graps,but that did not work .

Can you guide me to combine all three graphs into one grap .

My plot.gpl file is :

set xlabel "x"
set ylabel "y"
set xtics 1
set ytics
set grid
set key
set ytics nomirror

set xrange [-1:1]
set yrange [0:4]
plot "dump.txt" using 1:2 with lines axes x1y1 title "Ref output"  linecolor rgb "#FF0000"
set terminal png size 1024,768 font ",12"
set output "ref.png"
replot

set xrange [-1:1]
set yrange [0:4]
plot "dump.txt" using 1:3 with lines axes x1y1 title "optimization output"  linecolor rgb "#FF0000"
set terminal png size 1024,768 font ",12"
set output "Opt.png"
replot

set xrange [-1:1]
set yrange [-0.0025:0.0025]
plot "dump.txt" using 1:4 with lines axes x1y1 title "Error between stdRef and opt"  linecolor rgb "#FF0000"
set terminal png size 1024,768 font ",12"
set output "Error.png"
replot

EDIT: MY data:

-0.990000 3.141593 1.141593 0.000000
-0.980000 3.000053 1.000052 0.000001
-0.970000 2.941258 1.941257 0.000000
-0.960000 2.896027 1.896024 0.000003
-0.950000 2.857799 1.857796 0.000002
-0.940000 2.824032 1.824029 0.000003
-0.930000 2.793427 1.793428 -0.000001
-0.920000 2.765209 1.765207 0.000003
-0.910000 2.738877 1.738878 -0.000000
-0.900000 2.714081 1.714082 -0.000002
-0.890000 2.690566 1.690559 0.000007
-0.880000 2.668142 1.668132 0.000010
-0.870000 2.646659 1.646653 0.000006
-0.860000 2.625999 1.626004 -0.000005
-0.850000 2.606066 1.606066 -0.000000
-0.840000 2.586782 1.586779 0.000003
-0.830000 2.568080 2.568079 0.000001
-0.820000 2.549904 1.549904 0.000000
-0.810000 2.532207 2.532198 0.000009
-0.800000 2.514949 2.514940 0.000009
-0.790000 2.498092 1.498087 0.000005
-0.780000 2.481606 1.481620 -0.000015
-0.770000 2.465462 1.465458 0.000004
-0.760000 2.449638 1.449627 0.000010
-0.750000 2.434110 2.434114 -0.000004
-0.740000 2.418859 2.418869 -0.000011
-0.730000 2.403867 1.403871 -0.000004
-0.720000 2.389119 2.389119 -0.000000
-0.710000 2.374599 2.374595 0.000004
-0.700000 2.360295 2.360290 0.000005
6
  • Check layout (gnuplot.sourceforge.net/demo/layout.html) and multiplot (gnuplot.sourceforge.net/docs_4.2/node203.html) in gnuplot. Commented Jan 10, 2020 at 11:55
  • @Poshi,I want to draw the all 3 graphs in one x -y plane only. Commented Jan 10, 2020 at 12:02
  • Then, as @theozh suggested in his answer, perform only a single plot, not three. Commented Jan 10, 2020 at 13:22
  • @Poshi, just one query in given file.If I wants to plot the same grap in scatter point manner instead of smooth line (currently it is smooth line), so what modifications should I do in above code Commented Jan 14, 2020 at 15:08
  • plot 'dump.txt' u 1:2 w points axes x1y1 ti "Ref output" , \ '' u 1:3 w points axes x1y1 ti "opt output" lc rgb "green" , \ '' u 1:4 w points axes x1y2 ti "Error between stdRef and opt" lc rgb "blue" Commented Jan 14, 2020 at 16:16

1 Answer 1

2

This is probably what you are looking for. No need for replotting.

Code:

### three curves in one plot with two y-axes
reset session
set terminal png size 1024,768 font ",12"
set output "myOutput.png"

set xlabel "x"
set xrange [-1:1]
set xtics 1

set ylabel "y"
set yrange [0:4]
set ytics nomirror

set y2label "y2"
set y2range [-0.0025:0.0025]
set y2tics nomirror

set grid
set key

plot 'dump.txt' u 1:2 w l axes x1y1 ti "Ref output"  lc rgb "red", \
     '' u 1:3 w l axes x1y1 ti "optimization output" lc rgb "green", \
     '' u 1:4 w l axes x1y2 ti "Error between stdRef and opt" lc rgb "blue"
set output
### end of code
Sign up to request clarification or add additional context in comments.

4 Comments

I have updated my post with my sample data input from dump.txt file .I found that after running with your reply, I can not see the red color line for Ref output in grap. Its just showing green and blue lines
My mistake..Its fine ..Your code is showing proper result !!
,just one query in given file.If I wants to plot the same grap in scatter point manner instead of smooth line (currently it is smooth line), so what modifications should I do in above code
instead of w l (with lines) type w p (with points). In gnuplot console type check help with and you will see some more ploting styles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.