gnuplot bug (?) plotting datafile - gnuplot

I wrote the following "tmp.dat" datafile
\# 0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20
\#inFile;cn;mv;nr;nd;nn;fil;sep;m#enn=;m#enn=;n=;i=;aLea1=;rLea1=;amea1=;rmea1=;NbaLea1=;NbrLea1=;Nbamea1=;Nbrmea1=;rrmen3a1=
ex32new_DMLPG_beta3_der1emeno5/fort.501;0;?;?;?;?;0.0110485435;0.0078125;14;11.1540828402;4225;0;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00172
ex32new_DMLPG_beta3_der1emeno5/fort.501;1;0.0165088727;1745;64;0;0.0441941738;0.0078125;42;11.2126074499;1745;1;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00172
ex32new_DMLPG_beta3_der1emeno5/fort.501;2;0.0165088858;1726;64;0;0.0441941738;0.0078125;35;11.2027809965;1726;2;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00272
ex32new_DMLPG_beta3_der1emeno5/fort.501;3;0.0165088801;1724;64;0;0.0441941738;0.0078125;39;11.214037123;1724;3;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00372
ex32new_DMLPG_beta3_der1emeno5/fort.501;4;0.0165088766;1720;64;0;0.0441941738;0.0078125;34;11.1831395349;1720;4;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00472
ex32new_DMLPG_beta3_der1emeno5/fort.501;5;0.0165088776;1718;64;0;0.0441941738;0.0078125;32;11.1850989523;1718;5;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00572
ex32new_DMLPG_beta3_der1emeno5/fort.501;6;0.0165088822;1710;64;0;0.0441941738;0.0078125;34;11.216374269;1710;6;0.00898;0.00158;0.00205;0.00205;0.00898;0.00158;0.00205;0.00205;0.00672
My gnuplot script
set datafile separator ";"
set datafile missing "?"
set grid
set xlabel "coarsening level"
set ylabel "rrmen3a1"
set xrange [-1:7]
set yrange [*:*]
set terminal pdf color
set output "tmp.pdf"
plot \
"tmp.dat" using 2:21 index 0 with lp title columnheader(1), \
# EOF
does NOT plot the "first" point (0, 0.00172), only points x=1,...,6
Any hint?

The issue is with your plot line
plot "tmp.dat" using 2:21 index 0 with lp title columnheader(1)
This instructs gnuplot to use your first record (which does not include commented lines) to use as column labels. So your first data line is being interpreted as a header. If you do not want to reformat your datafiles, you can plot a dummy curve with the same header file which will act as your data series label. Something like
plot "tmp.dat" using 2:21 index 0 with lp lt 1 lc rgb 'black' notitle, \
"tmp.dat" using ($0):(1/0) index 0 with lp lt 1 lc rgb 'black' columnhead(1)
Note that we have to manually specify the line styles to ensure the keys have the same linestyle as the curves.

Related

How can I keep previous plot in gnuplot

Need to mark with circle on graph, but it doesn't overlap
#set multiplot layout 2, 1 # engage multiplot mode
#set multiplot
set font "arial,12"
set autoscale
set datafile separator comma
#set offset 0,0,.5,.5
#set autoscale fix
set xtics out nomirror
set ytics out nomirror
unset border
set border 3
set format y "%0.04s %cV "
set format x
#set object circle at 5.2055,3430 size 25.5 lw 5 fc rgb "red"
$data <<EOD
3400,5.2055
EOD
plot [3200:4400] "shurb/foo.csv" u 1:2 w l lc rgb 'dark-green' title 'AP',\
$data using 1:2 with circle lw 1 lc rgb 'red' notitle' ,
#unset multiplot
#set output
It is only drawing second one or first one, so I have to merge them on same plot.
How can I mark with circle or merge these two plots? Why I couldn't overlap them.
Maybe I cannot fully follow what you are trying to do. How do you get two plot with a single plot command?
There is no need to use multiplot. Simply plot your datafile and your datablock $data with a single datapoint.
By the way, your commented #set object circle at 5.2055,3430 size 25.5 lw 5 fc rgb "red" has swapped x-, and y-coordinates. So, this circle object would not be visible on your plot.
Script: (works with gnuplot>=5.2.2)
### plot with circles
reset session
# create some test data
set table $Test separator comma
plot [3200:4400] '+' u 1:(sin($0/6)*cos($0/20)/2.8*0.005+5.205) w table
unset table
$data <<EOD
3400, 5.2055
EOD
set datafile separator comma
set format y "%.4f mV"
set key noautotitle
plot [3200:4400] $Test u 1:2 w l lc "dark-green", \
$data u 1:2 w circle lw 1 lc "red"
### end of script
Result:

Gnuplot set a plot with linecolors

i have encountered a strange problem which i cannot overcome.
I'm plotting data from 4 files into 1 and i want every plot to have a different linecolor. However command lt #some number just doesn't work, it gives different linetypes but never colours.
I'm using a script to make a file, to pipe it inside gnuplot to yield a .ps file.
set terminal postscript
set encoding iso_8859_1
set title 'energy difference for a polymer'
set xlabel 'n, polymer length'
set ylabel '{/Symbol D}E, eV'
set key bottom left
set xzeroaxis
set output 'deltaE_PQL.ps'
set boxwidth 0.9 relative
set style fill solid 1.0
plot 'deltaE_plotm2' u 1:2 with lines lt 1 title '| -2 {/Symbol \361}', \
'deltaE_plotm1' u 1:2 with lines lt 2 title '| -1 {/Symbol \361}', \
'deltaE_plot1' u 1:2 with lines lt 3 title '| 1 {/Symbol \361}', \
'deltaE_plot2' u 1:2 with lines lt 4 title '| 2 {/Symbol \361}'
Appreciate any ideas what is wrong here.
In gnuplot console type and check help postscript and use:
set terminal postscript color

Plot a forecast line with Gnuplot?

I've this data :
Serv1;2019-10;2561.36
Serv1;2019-11;3292.65
Serv1;2019-12;3077.58
Serv1;2020-01;3369.98
Serv1;2020-02;3134.53
Serv1;2020-03;593.332
With excel, I'm able to create an graph with a forecast line on excel like that :
I'm able to create a graph with gnuplot :
With this gnuplot script :
set title "test"
set terminal png truecolor size 960,720 background rgb "#eff1f0"
set output "/xxx/xxx/xxx/xxx/xxx/test.png"
set grid
set style line 1 \
linecolor rgb '#0060ad' \
linetype 1 linewidth 2 \
pointtype 7 pointsize 1.5
set offsets 0.5,0.5,0,0.5
set datafile separator ";"
set key left
plot "test.txt" using 3:xtic(2) with linespoints linestyle 1
But I don't know how to plot a forecast line with Gnuplot...
Could you show me how to do that ?
Assuming you are looking for a linear fit and extending this linear function, you can try the following below.
Edit:
There is no gnuplot function to get the data value of a certain row and column, e.g. like a = value(row,column). You have to use a somehow strange workaround. Basically, you plot your data into a dummy table, but only the first datapoint of the first block of the first dataset (counting starts with 0). Check help every and help index.
set table $Dummy
plot $Data u (StartDate=timecolumn(1,myTimeFmt)) index 0 every ::0:0:0:0 w table
unset table
print sprintf("StartDate: %s",strftime(myTimeFmt,StartDate))
Result: StartDate: 01/03/2020
Code:
### linear fit and extrapolation
reset session
$Data <<EOD
01/03/2020,100
02/03/2020,150
03/03/2020,125
04/03/2020,150
05/03/2020,175
06/03/2020,200
07/03/2020,220
08/03/2020,150
09/03/2020,175
10/03/2020,125
11/03/2020,150
12/03/2020,200
13/03/2020,210
14/03/2020,230
EOD
set datafile separator comma
myTimeFmt = "%d/%m/%Y"
set format x "%d.%m." time
# put start date into variable StartDate
set table $Dummy
plot $Data u (StartDate=timecolumn(1,myTimeFmt)) index 0 every ::0:0:0:0 w table
unset table
EndDate = strptime("%Y-%m","30/04/2020")
f(x) = a*(x-StartDate)+ b
set fit quiet nolog
fit f(x) $Data u (timecolumn(1,myTimeFmt)):2 via a,b
set xrange[StartDate:EndDate]
set grid xtics, ytics
plot $Data u (timecolumn(1,myTimeFmt)):2 w lp pt 7 lc rgb "red" notitle, \
[StartDate:EndDate] f(x) ti "linear fit with extrapolation"
### end of code
Result:
Edit 2: (version for gnuplot 4.6)
Modified for gnuplot 4.6. Where I got problems and found out later is the parameter FIT_LIMIT = 1e-8 which you need to set for fitting timedata.
Data: (Data.dat)
Serv1;2019-10;2561.36
Serv1;2019-11;3292.65
Serv1;2019-12;3077.58
Serv1;2020-01;3369.98
Serv1;2020-02;3134.53
Serv1;2020-03;593.332
Code:
### linear fit and extrapolation, version for gnuplot 4.6
reset
FILE = "Data.dat"
set datafile separator ";"
set xdata time
set timefmt "%Y-%m"
set format x "%Y\n%m"
# put start date into variable StartDate, dummy plot
plot FILE u (StartDate=timecolumn(2)):0 index 0 every ::0:0:0:0
EndDate = strptime(myTimeFmt,"2020-09")
f(x) = a*(x-StartDate) + b
FIT_LIMIT = 1e-8
fit f(x) FILE u (timecolumn(2)):3 via a,b
set xrange[StartDate:EndDate]
set grid xtics, ytics
set yrange[0:4000]
plot FILE u (timecolumn(2)):3 w lp pt 7 lc rgb "red" notitle, \
f(x) ti "linear fit with extrapolation"
### end of code
Result:

Plot boolean values on a time based line graph

I am plotting a time based line graph and would like to add a boolean data series to it.
Is it possible to have the boolean data highlight the full height of the canvas of the graph where the value is true?
Plotfile:
set datafile separator ","
set terminal pngcairo size 800,400
set title "Solar charge monitor"
set yrange [0:]
set ylabel "V"
set y2range [0:]
set y2label "A"
set y2tics
set xlabel "Date"
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%SZ"
set key left top
set grid
set output "samplePlot.png"
plot "sampleData.csv" using 1:2 with lines lw 2 title 'Batt (V)', \
"sampleData.csv" using 1:3 with lines lw 2 title 'Solar (V)', \
"sampleData.csv" using 1:4 with lines lw 2 title 'Charge (A)' axes x1y2, \
"sampleData.csv" using 1:5 with lines lw 2 title 'Load (A)' axes x1y2
Sample Data:
time,V_Batt,V_SolarV,A_Charge,A_Load,bool_charging
2014-09-25T07:06:03.358Z,13.20,14.38,0.52,0.03,1
2014-09-25T07:05:03.639Z,13.16,14.14,0.52,0.05,1
2014-09-25T07:04:02.856Z,13.18,14.19,0.54,0.03,1
2014-09-25T07:03:03.141Z,13.18,14.24,0.52,0.03,1
2014-09-25T07:02:03.410Z,13.18,14.09,0.52,0.03,1
2014-09-25T07:01:03.604Z,13.20,14.38,0.54,0.03,1
2014-09-25T07:00:02.766Z,13.11,14.28,0.50,0.02,1
2014-09-25T06:59:03.025Z,13.09,14.28,0.48,0.02,1
2014-09-25T06:58:03.302Z,13.11,14.28,0.43,0.02,1
2014-09-25T06:57:03.445Z,13.18,14.28,0.56,0.05,1
2014-09-25T06:56:02.611Z,13.16,14.14,0.52,0.03,1
2014-09-25T06:55:02.901Z,13.09,14.58,0.48,0.01,1
2014-09-25T06:54:03.178Z,13.09,14.48,0.52,0.02,1
2014-09-25T06:53:03.432Z,13.13,14.53,0.54,0.06,1
2014-09-25T06:52:03.630Z,13.11,14.28,0.48,0.03,1
2014-09-25T06:51:02.763Z,13.16,14.14,0.54,0.05,1
2014-09-25T06:50:03.068Z,13.16,14.28,0.54,0.03,1
2014-09-25T06:49:03.388Z,13.07,14.38,0.50,0.03,1
2014-09-25T06:48:02.683Z,13.09,14.33,0.50,0.03,1
2014-09-25T06:47:02.967Z,13.07,14.04,0.48,0.02,1
2014-09-25T06:46:03.249Z,13.05,14.19,0.48,0.02,1
2014-09-25T06:45:03.410Z,13.09,14.24,0.56,0.06,1
2014-09-25T06:44:02.677Z,13.07,14.24,0.52,0.03,1
2014-09-25T06:43:02.973Z,13.05,14.09,0.50,0.03,1
2014-09-25T06:42:03.282Z,13.09,14.24,0.52,0.03,1
2014-09-25T06:41:03.389Z,12.96,14.04,0.46,0.02,1
2014-09-25T06:40:02.702Z,12.76,13.59,0.50,0.00,1
I would like to add column 6 which is a boolean (0/1) value. In this sample data, the background would be fully highlighted as the bool is always true
Any tips?
You can use the boxes plotting style to draw background boxes depending on the value of column 6, i.e. something like
plot "sampleData.csv" using 1:($6 * 16) with boxes fc rgb '#ccffcc' fillstyle solid,\
"" using 1:2 lt 1 with lines lw 2 title 'Batt (V)'
That, however, requires you to know the maximum and minimum values of the y-range. If that should be calculated automatically, you'll need first to make a dummy plot with the unknown terminal and then use GPVAL_Y_MIN and GPVAL_Y_MAX:
reset
set datafile separator ","
set terminal pngcairo size 800,400
set title "Solar charge monitor"
set yrange [0:]
set ylabel "V"
set y2range [0:]
set y2label "A"
set y2tics
set xlabel "Date"
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%SZ"
set key left center
set grid
set autoscale xfix
set style data lines
set terminal push
set terminal unknown
plot "sampleData.csv" using 1:2, "" using 1:3
set terminal pop
set output "samplePlot.png"
plot "sampleData.csv" using 1:(GPVAL_Y_MIN + $6 * (GPVAL_Y_MAX - GPVAL_Y_MIN)) with boxes fc rgb '#ccffcc' fillstyle solid notitle,\
"" using 1:2 lt 1 lw 2 title 'Batt (V)', \
"" using 1:3 lt 2 lw 2 title 'Solar (V)', \
"" using 1:4 lt 3 lw 2 title 'Charge (A)' axes x1y2, \
"" using 1:5 lt 4 lw 2 title 'Load (A)' axes x1y2
Using a slightly changed data file (I inserted some zeros to show the effect), I get:
If you don't want vertical lines at the boundaries, you could also use filledcurves with:
...
plot "sampleData.csv" using 1:(GPVAL_Y_MIN + $6 * (GPVAL_Y_MAX - GPVAL_Y_MIN)) with filledcurves x1 fc rgb '#ccffcc' fillstyle solid notitle,
...

gnuplot: Not enough columns for variable color

I am executing the following gnuplot script:
set title "Efficiency scatter plot"
set xlabel "perf_1"
set ylabel "secondary report"
set log x
set log y
set xrange [0.1:40.0]
set yrange [0.1:40.0]
set terminal png medium
set output "./graph1.png"
set size square
set multiplot
set pointsize 0.3
set style line 6 pt 6
set datafile separator ","
set border 3
set xtics nomirror
set ytics nomirror
plot '/tmp/data.csv' using 3:1 with points pt 1 lt 3 lc var title "perf_20140113131309", \
'/tmp/data.csv' using 3:2 with points pt 1 lt 1 lc var title "perf_1"
plot x notitle
plot 2*x notitle
plot 0.5*x notitle
obtaining the following error message
"script.gnuplot", line 20: Not enough columns for variable color
Could you please guide me in order to find what I am doing wrong.
By the way the gnuplot version is '4.6 patchlevel 3' the data.csv files used is
0.1,0.1,40.0
0.14,0.14,40.0
0.32,0.32,40.0
0.7,0.74,40.0
Thanks in advance!
That means, that you need to specify one more column in your using statement: The first one is the x-coordinate, the second one the y-coordinate. The one for the variable line color is missing.
Use e.g.
plot '/tmp/data.csv' using 3:1:0 with points pt 1 lt 3 lc var
to use the row number (zeroth column) as linetype index. You can also use e.g. linecolor palette so select the color from the currently defined color palette.

Resources