How to fix : " could not open log-file fit.log: " with Gnuplot 4.6 and AIX 7.2? - linux

With RedHat and Gnuplot 4.6, I've these data :
2019-08-30,384.00,225.3
2019-08-31,394.00,225.3
2019-09-01,406.00,225.3
2019-09-02,424.00,225.3
2019-09-03,439.00,225.29
2019-09-04,454.00,234.34
2019-09-05,484.00,234.34
And this script :
set title "test"
set terminal png truecolor size 960,720 background rgb "#eff1f0"
set output "/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 style line 2 \
linecolor rgb "red" \
linetype 1 linewidth 1 \
pointtype 7 pointsize 1
set offsets 0.5,0.5,0,0.5
set datafile separator ","
set format y "%g"
set key left
myLabel(n) = sprintf("%g",n)
plot "df_output.txt" using 2:xtic(1) with linespoints linestyle 1 ,\
'' using 3:xtic(1) with linespoints linestyle 2 title " Free space ", \
'' using 0:2:(myLabel($2)) w labels offset 0,-0.5 notitle, \
'' using 0:3:(myLabel($3)) w labels offset 0,1 notitle, \
The result is :
I would like to put a trendline on the blue curve, So my script looks like :
set title "test"
set terminal png truecolor size 960,720 background rgb "#eff1f0"
set output "/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 style line 2 \
linecolor rgb "red" \
linetype 1 linewidth 1 \
pointtype 7 pointsize 1
set offsets 0.5,0.5,0,0.5
set datafile separator ","
set format y "%g"
set key left
myLabel(n) = sprintf("%g",n)
f(x) = a*x + b
fit f(x) "df_output.txt" u 0:2 via a,b
plot "df_output.txt" using 2:xtic(1) with linespoints linestyle 1 ,\
'' using 3:xtic(1) with linespoints linestyle 2 title " Free space ", \
'' using 0:2:(myLabel($2)) w labels offset 0,-0.5 notitle, \
'' using 0:3:(myLabel($3)) w labels offset 0,1 notitle, \
f(x) w l lc "black" title "trendline"
And that works perfectly :
Without the f function and the same datas, this script works perfectly with AIX 7.2 but with the f function, I've this error in my error_log file :
Could not open log-file fit.log:
And if I try to generate manually the graph, I've this error :
Singular matrix in Invert_RtR
"gnuplot_script.txt", line 25:
The line 25 is :
fit f(x) "df_output.txt" u 0:2 via a,b
Du you have any idea about this problem ?

Related

GNUPLOT draws step plot not within border restrictions

Drawing a step plot leads always to an out of border result.
How to solve the issue? Any ideas? THX!
The MWE is:
reset;set term png small size 500,500;set output 'test.png';
set title 'First step is always drawn out of chart borders ?!?';
unset y2tics;set y2range [0:40];set y2tics 10;set yrange [0:40];set ytics 10 mirror;
set style fill solid 1.00 border;
plot 'test.data' using 1:2 notitle with fillsteps lc rgb 'light-goldenrod', \
'' using 1:3 notitle with fillsteps lc rgb 'gray40', \
'' using 1:4 notitle with fillsteps lc rgb 'web-green', \
'' using 1:5 notitle with fillsteps lc rgb 'light-green';
The result is:
Used software is:
GNUPLOT Version 5.2 patchlevel 8
Ok, now I see your point. Looks like a little bug (or our limited understanding).
I cannot tell right away why this is, but you can avoid it
by adding a line in the beginning which contains the first x value and all y-values are 0.
If you don't want to do this manually, there would be ways to do this automatically with gnuplot.
But I hope there is a simpler solution.
Code:
### plot with fillsteps
reset session
$Data <<EOD
1 0 0 0 0
1 50 35 30 5
2 55 30 20 5
17 51 44 30 12
20 1 1 1 1
EOD
unset y2tics;set y2range [0:40]
set y2tics 10
set yrange [0:40]
set ytics 10 mirror
set style fill solid 1.00 border
unset key
plot $Data u 1:2 w fillsteps lc 'light-goldenrod', \
'' u 1:3 w fillsteps lc 'gray40', \
'' u 1:4 w fillsteps lc 'web-green', \
'' u 1:5 w fillsteps lc 'light-green'
### end of code
Result:
Addition: (automatically duplicate first line, to workaround the bug(!?))
In order to workaround this (what I would call unexpected or a bug) you want to duplicate the first line automatically. There would be certainly different easy ways with external tools, however, which would not guarantee platform-independence. So, here is one of several possible gnuplot-only solutions.
get your file into a datablock (here: $Data) (see gnuplot: load datafile 1:1 into datablock)
print the first line of $Data into a new datablock (here: $Data2) Make sure that the first line is not a header or commented line, i.e. print the first dataline.
append the full datablock $Data again to $Data2.
Data: (Test.dat)
1 50 35 30 5
2 55 30 20 5
17 51 44 30 12
20 1 1 1 1
Code: (Result same as above)
# https://stackoverflow.com/a/67151340/7295599
### plot with filledcurves
reset session
FileToDatablock(f,d) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
sprintf('< echo %s ^<^<EOD & type "%s"',d,f) : \
sprintf('< echo "\%s <<EOD" & cat "%s"',d,f) # Linux/MacOS
FILE = 'Test.dat'
load FileToDatablock(FILE,'$Data')
set print $Data2
print $Data[1] # only first line
print $Data
set print
unset y2tics;set y2range [0:40]
set y2tics 10
set yrange [0:40]
set ytics 10 mirror
set style fill solid 1.00 border
unset key
plot $Data2 u 1:2 every ::0::0 w fillsteps lc 'light-goldenrod', \
'' u 1:2 w fillsteps lc 'light-goldenrod', \
'' u 1:3 w fillsteps lc 'gray40', \
'' u 1:4 w fillsteps lc 'web-green', \
'' u 1:5 w fillsteps lc 'light-green'
### end of code

Linked top x-axis in Gnuplot

My test.dat file is given below
6.78E-01 -1.907881356 -1.938152542 -1.994762712 -4.409491525 -3.707118644 -2.623559322 -1.903389831 -1.891452492 -1.880469492 -2.009079661 -1.835169492 -2.193627119
6.73E-01 -1.828333333 -1.861727273 -1.916205387 -4.308956229 -3.614276094 -2.547508418 -1.823097643 -1.811922731 -1.800939731 -1.930919529 -1.757255892 -2.114855219
6.69E-01 -1.749849498 -1.786324415 -1.838698997 -4.209765886 -3.522675585 -2.472474916 -1.743879599 -1.733456913 -1.722473913 -1.853805017 -1.680384615 -2.037137124
6.64E-01 -1.672408638 -1.711923588 -1.762222591 -4.111893688 -3.432292359 -2.398438538 -1.665714286 -1.656033831 -1.645050831 -1.777715282 -1.604534884 -1.960451827
6.60E-01 -1.595990099 -1.63850495 -1.686755776 -4.015313531 -3.34310231 -2.325379538 -1.588580858 -1.579632835 -1.568649835 -1.702630033 -1.529686469 -1.884778878
6.56E-01 -1.52057377 -1.56604918 -1.612278689 -3.92 -3.255081967 -2.253278689 -1.512459016 -1.50423382 -1.49325082 -1.628529508 -1.455819672 -1.810098361
6.51E-01 -1.446140065 -1.494537459 -1.538771987 -3.825928339 -3.168208469 -2.182117264 -1.43732899 -1.429817202 -1.418834202 -1.555394463 -1.382915309 -1.736390879
6.47E-01 -1.372669903 -1.423951456 -1.466216828 -3.733074434 -3.082459547 -2.111877023 -1.363171521 -1.356363906 -1.345380906 -1.483206149 -1.310954693 -1.66363754
6.43E-01 -1.300144695 -1.354273312 -1.394594855 -3.641414791 -2.997813505 -2.042540193 -1.289967846 -1.283855347 -1.272872347 -1.411946302 -1.239919614 -1.591819936
6.39E-01 -1.228546326 -1.285485623 -1.323888179 -3.550926518 -2.914249201 -1.974089457 -1.217699681 -1.212273415 -1.201290415 -1.341597125 -1.169792332 -1.520920128
6.35E-01 -1.157857143 -1.217571429 -1.254079365 -3.461587302 -2.831746032 -1.906507937 -1.146349206 -1.14160046 -1.13061746 -1.27214127 -1.100555556 -1.450920635
6.31E-01 -1.088059937 -1.150514196 -1.18515142 -3.373375394 -2.750283912 -1.83977918 -1.075899054 -1.071819278 -1.060836278 -1.20356183 -1.032192429 -1.381804416
6.27E-01 -1.019137931 -1.084297806 -1.117087774 -3.286269592 -2.66984326 -1.773887147 -1.006332288 -1.002913094 -0.991930094 -1.13584232 -0.96468652 -1.313554859
6.23E-01 -0.951074766 -1.018906542 -1.049872274 -3.200249221 -2.590404984 -1.708816199 -0.937632399 -0.934865555 -0.923882555 -1.068966667 -0.898021807 -1.246155763
6.19E-01 -0.883854489 -0.954325077 -0.983489164 -3.115294118 -2.511950464 -1.644551084 -0.869783282 -0.867660709 -0.856677709 -1.002919195 -0.832182663 -1.179591331
6.15E-01 -0.817461538 -0.890538462 -0.917923077 -3.031384615 -2.434461538 -1.581076923 -0.802769231 -0.801283 -0.7903 -0.937684615 -0.767153846 -1.113846154
6.12E-01 -0.751880734 -0.82753211 -0.853159021 -2.948501529 -2.357920489 -1.518379205 -0.736574924 -0.735717251 -0.724734251 -0.873248012 -0.702920489 -1.048905199
6.08E-01 -0.687097264 -0.765291793 -0.789182371 -2.86662614 -2.28231003 -1.456443769 -0.67118541 -0.670948653 -0.659965653 -0.809594833 -0.639468085 -0.984753799
6.04E-01 -0.623096677 -0.703803625 -0.725978852 -2.785740181 -2.207613293 -1.395256798 -0.606586103 -0.606962758 -0.595979758 -0.746710876 -0.576782477 -0.921377644
I use the following code in gnuplot to check the plot
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,5in
set output "Plot1.eps"
set xtics out scale 1.5
set ytics out scale 1.5
set tics font ", 16"
set xlabel "10^{3}{/Symbol \264} 1/T (K^{-1})" font ",16"
set ylabel "log&{t}{/Times-Italic p}_{Pu({/Times-Italic g}),Pa} " font ",16"
set key outside right top
set key maxrows 12 spacing 2.1 font ",16" width -2
plot [0.60:0.70] 'test.dat.dat' u 1:2 with points pt 1 ps 1.75 lt rgb "red" title "Maeda {/Times-Italic et al.} [7]", \
'' u 1:3 with points pt 1 ps 1.75 lt rgb "blue" title "Pu-20Zr [7]", \
'' u 1:4 with points pt 1 ps 1.75 lt rgb "dark-green" title "Pu-50Zr [7]", \
'' u 1:5 with points pt 2 ps 1.75 lt -1 title "Present work", \
'' u 1:6 with points pt 3 ps 1.75 lt -1 title "Present work", \
'' u 1:7 with points pt 4 ps 1.75 lt rgb "red" title "Alcock [16]", \
'' u 1:8 with points pt 4 ps 1.75 lt rgb "blue" title "Phipps {/Times-Italic et al.} [19]", \
'' u 1:9 with points pt 4 ps 1.75 lt rgb "dark-green" title "Mulford [20]", \
'' u 1:10 with points pt 5 ps 1.75 lt rgb "blue" title "Kent [21]", \
'' u 1:11 with points pt 5 ps 1.75 lt rgb "red" title "Ackermann and Rauh [22]", \
'' u 1:12 with points pt 5 ps 1.75 lt rgb "dark-green" title "Bradbury and Ohse [23]", \
'' u 1:13 with points pt 5 ps 1.75 lt -1 title "Kim and Hofman [24]"
The code runs well. One can see that x axis is related to temperature as 1000/temperature. Now I wanted a linked top x2-axis with temperature in K. So, for example, xrange is from 0.6 to 0.7. Then x2 axis should be from 1000/0.6 to 1000/0.7 i.e. from 1666.67 K to 1428.57 K. So I modified the code based on linkedaxes.dem.
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,5in
set output "Plot2.eps"
set xtics out scale 1.5
set ytics out scale 1.5
set tics font ", 16"
set xtics nomirror
set xlabel "10^{3}{/Symbol \264} 1/T (K^{-1})" font ",16"
set ylabel "log&{t}{/Times-Italic p}_{Pu({/Times-Italic g}),Pa} " font ",16"
set key outside right top
set key maxrows 12 spacing 2.1 font ",16" width -2
set link x2 via 1000./x inverse 1000./x
set x2tics out scale 1.5
set x2label "Temperature (K)" font ",16"
plot [0.60:0.70] 'test.dat' u 1:2 with points pt 1 ps 1.75 lt rgb "red" title "Maeda {/Times-Italic et al.} [7]", \
'' u 1:3 with points pt 1 ps 1.75 lt rgb "blue" title "Pu-20Zr [7]", \
'' u 1:4 with points pt 1 ps 1.75 lt rgb "dark-green" title "Pu-50Zr [7]", \
'' u 1:5 with points pt 2 ps 1.75 lt -1 title "Present work ", \
'' u 1:6 with points pt 3 ps 1.75 lt -1 title "Present work", \
'' u 1:7 with points pt 4 ps 1.75 lt rgb "red" title "Alcock [16]", \
'' u 1:8 with points pt 4 ps 1.75 lt rgb "blue" title "Phipps {/Times-Italic et al.} [19]", \
'' u 1:9 with points pt 4 ps 1.75 lt rgb "dark-green" title "Mulford [20]", \
'' u 1:10 with points pt 5 ps 1.75 lt rgb "blue" title "Kent [21]", \
'' u 1:11 with points pt 5 ps 1.75 lt rgb "red" title "Ackermann and Rauh [22]", \
'' u 1:12 with points pt 5 ps 1.75 lt rgb "dark-green" title "Bradbury and Ohse [23]", \
'' u 1:13 with points pt 5 ps 1.75 lt -1 title "Kim and Hofman [24]"
But the set link does not give the computed values on the top x2 axis. What modifications in code need to be made?
It looks like for some reason (which I don't know) you have to give an increment for the x2tics.
Try the following minimal example:
Code:
### link x2 axis
reset session
set xrange[0.6:0.7]
set xtics nomirror
set link x2 via 1000./x inverse 1000./x
set x2tics 50
plot x
### end of code
Result:

Gnuplot histogram with plot line

I am using Gnuplot to create a histogram with a plot line, however, the plot line is not fit well with bar head, also I would like to put the line a little bit far from the bar head.
set border 3
set boxwidth 0.9
set tics nomirror out scale 0.75
set style fill solid 0.8
plot "03.txt" using 2:xtic(1) lt rgb "#0060ad" notitle, "" using 2 smooth csplines notitle with lines ls 1, "" using 3 lt rgb "#ff6600" notitle, "" using 3 smooth csplines notitle with lines ls 2, "" using 4 lt rgb "#dd181f" notitle, "" using 4 smooth csplines notitle with lines ls 3
Updated:
This is the data file:
500000 25.938 25.938 2
1000000 52.385 52.385 4
1500000 79.749 78.405 6.125
2000000 152.589 100.261 12.479
2500000 224.869 118.364 19.159
This should work for any number of columns, you have to specify them in the variable N, and number them in calls to custom function xbox. This should do for a non-intensive usage. You can offset vertically the curves with the OFFSET variable (in units of y axis)
set border 3
#number of columns to be plotted
N=3
#vertical offset
OFFSET=0
#gapwidth (set to gnuplot's default)
GW=2
xbox(x,i)=x+(i-N*0.5)/(N+GW)
set boxwidth 0.9
set tics nomirror out scale 0.75
set style fill solid 0.8
plot "03.txt" using 2:xtic(1) lt rgb "0060ad" notitle, \
"" using 2 with histogram notitle, \
"" using (xbox($0,1)):($2+OFFSET) smooth csplines notitle with lines ls 1, \
"" using 3 lt rgb "#ff6600" notitle with histogram, \
"" using (xbox($0,2)):($3+OFFSET) smooth csplines notitle with lines ls 2, \
"" using 4 lt rgb "#dd181f" notitle with histogram, \
"" using (xbox($0,3)):($4+OFFSET) smooth csplines notitle with lines ls 3

Same Gnuplot linestyle as in graph in key/legend

I would like to plot a legend/key, which shows the different symbols on the line. Currently my plots look like this:
Unfortunately the symbols (triangle, rectangle and circle) are not shown in the key/legend. How is it possible to add them?
I use the following gnuplot script:
set title tit font "palatino,20"
set xlabel xlbl font "palatino,20"
set ylabel ylbl font "palatino,20"
#set logscale x
set output graphfilename.".pdf"
set terminal pdf
set border linewidth 2
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 # --- blue
set style line 2 lc rgb '#00ad60' lt 1 lw 2 pt 7 # red .
set style line 3 lc rgb '#ad0000' lt 1 lw 2 pt 9 # green .
set tics scale 0.8
set key below
plot file1 using ($1/1000):($2/1000000):($3/1000000):($4/1000000) notitle w yerrorbars ls 1, \
'' using ($1/1000):($2/1000000) title "Hlog" w lines ls 1,\
file2 using ($1/1000):($2/1000000):($3/1000000):($4/1000000) notitle w yerrorbars ls 2, \
'' using ($1/1000):($2/1000000) title "Iris" w lines ls 2,\
file3 using ($1/1000):($2/1000000):($3/1000000):($4/1000000) notitle w yerrorbars ls 3, \
'' using ($1/1000):($2/1000000) title "Java" w lines ls 3
Generally, you can get both lines and points, if you plot with the linespoints plotting style:
sc(x) = x*1e-6
plot file1 using ($1/1000):(sc($2)):(sc($3)):(sc($4)) notitle w yerrorbars ls 1 ps 0.5, \
'' using ($1/1000):(sc($2)) title "Hlog" w linespoints ls 1
That draws the points twice, which shouldn't be a problem unless you use transparency. I also shrinked the points which are drawn together with the errorbars to 50%, so you don't get problems with antialiasing.
As another option you could add the title only the the errorbars, in which case the legend would look like |---x---| (i.e. contain also the errorbars):
sc(x) = x*1e-6
plot file1 using ($1/1000):(sc($2)):(sc($3)):(sc($4)) title "Hlog" w yerrorbars ls 1, \
'' using ($1/1000):(sc($2)) notitle w lines ls 1

gnuplot box-and-whisker clustered

I am trying to plot a clustered box-and-whisker plots in gnuplot for two files and I want the outputs to share the same xtics. Instead, I get an xtic for each file. This is my script:
set term pdf color enhanced
#set output ".pdf"
set bar 2
set style fill empty
set ylabel "Link Speed (kbps)"
set xlabel "Rate (Mbps)"
set grid
plot "file1.txt" using ($1-0.05):5:4:10:9:xticlabels(2) with candlesticks title "video" whiskerbars lw 3 lt 2, \
"" using ($1-0.05):7:7:7:7:xticlabels(2) with candlesticks lt 2 lw 5 notitle, \
"" using ($1-0.05):3:xticlabels(2) with points lt 18 pt 7 ps 0.7 notitle, \
"file2.txt" using ($1+0.05):5:4:10:9:xticlabels(2) with candlesticks title "tcp" whiskerbars lw 3 lt 3, \
"" using ($1+0.05):7:7:7:7:xticlabels(2) with candlesticks lt 3 lw 5 notitle, \
"" using ($1+0.05):3:xticlabels(2) with points lt 18 pt 7 ps 0.7 notitle

Resources