Linked top x-axis in Gnuplot - 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:

Related

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

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 ?

Gnuplot line and key colors

I'm trying to use Gnuplot to create a line chart. Each line is represented by a different color. What I want is the key has the same color as the line color. This is what I have right now, current version. Is it possible to set the text 'Line 2' colored as orange, 'Line 3' colored as red, etc?
This is what I wrote in the gp file:
set xlabel'x-axis'; \
set xrange[0:25];\
set ylabel 'y-axis';\
set yrange [2:9];\
set key left top;
p 'test.dat' using 1:2 w linespoints lw 5 lc rgb '#aadc32' pt 17 title 'Line 1' ,\
'test.dat' using 1:9 w linespoints lw 5 lc 'orange' lt 1 title 'Line 2',\
'test.dat' using 1:6 w linespoints lw 5 lc 'red' lt 8 title 'Line 3',\
'test.dat' using 1:7 w linespoints lw 5 lc 'violet' pt 6 title 'Line 4',\'test.dat' using 1:8 w linespoints lw 5 lc rgb '#b5367a' pt 19 title 'Line 5',\
'test.dat' using 1:3 w linespoints lw 5 lc 'cyan' pt 9 title'Line 6',\
'test.dat' using 1:4 w linespoints lw 5 lc 'blue' lt 9 title 'Line 7',\
'test.dat' using 1:10 w linespoints lw 5 lc rgb '#1c1044' lt 5 title 'Line 8',\
Thank you so much.
Unfortunately not. The plot title does not (now, gp5.2pl0) recognise the "textcolor" specifier.
plot x lw 3 lc rgb "blue" title "x" tc rgb "blue" # doesn't work
You can only print an empty (" ") plot title, and overprint it with a coloured label
set label 1 at 8,1 "bluetitle" tc rgb "blue"
That requires some fiddling with the placement of the label, of course.
You might put up a feature request on https://sourceforge.net/p/gnuplot/feature-requests/

How to make key colour black in Gnuplot

How can I make the key "symbols" black in colour when using palettes?
I think you cannot control this directly, here a workaround:
plot 'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt black, \
'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt palette notitle
So, we first plot the data without legend in black, then plot the data points but no legend. The nice thing about this approach is that there is no need to fix the x or y range.
I would just create a dummy line and use notitle on the real lines. Something like
set yrange[0:1]
plot "realdata1.data" u 1:2 w linespoints lt 1 notitle , \
"realdata2.data" u 1:2 w linespoints lt 2 notitle , \
1/0 w linespoints lt 1 lc rgb 'black' title 'Model1', \
1/0 w linespoints lt 1 lc rgb 'black' title 'Model2'
Then replace lt 1 with whatever you have used for style in your current plot. Note that you'll need to use set yrange for gnuplot to accept the dummy curve

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

Point color in gnuplot 4.0

When I try to plot three separate data files using gnuplot, I get an error "';' expected" in the output when I try to change the point color of the data sets.
For example, this works fine:
set terminal jpeg size 900,500
set xlabel 'x axis label'
set ylabel 'y axis label'
set title 'sample title'
set output "output.jpeg"
set xrange [-0.1:1.1]
set yrange [] reverse
set xtics 0.10
#set ytics 100
set key top left
set grid ytics lt 0 lw 1
set grid xtics lt 0 lw 1
plot 'file1.dat' u 1:2 w p pt 7 ps 0.8 ti 'dataset 1', \
'file2.dat' u 1:2 w p pt 6 ps 0.8 ti 'dataset 2', \
'file3.dat' u 1:2 w p pt 5 ps 0.8 ti 'dataset 3'
This does not:
set terminal jpeg size 900,500
set xlabel 'x axis label'
set ylabel 'y axis label'
set title 'sample title'
set output "output.jpeg"
set xrange [-0.1:1.1]
set yrange [] reverse
set xtics 0.10
#set ytics 100
set key top left
set grid ytics lt 0 lw 1
set grid xtics lt 0 lw 1
plot 'file1.dat' u 1:2 w p pt 7 ps 0.8 lc 9 ti 'dataset 1', \
'file2.dat' u 1:2 w p pt 6 ps 0.8 ti 'dataset 2', \
'file3.dat' u 1:2 w p pt 5 ps 0.8 ti 'dataset 3'
Why is this? Is there a workaround to simply change point color independent of point style and size?
Thanks!
The keyword linecolor (lc) was introduced in version 4.2. In your case you can change the color using linetype (lt):
set terminal jpeg size 900,500
set output "output.jpeg"
plot 'file1.dat' u 1:2 w p pt 7 ps 0.8 lt 9 ti 'dataset 1'
But I also strongly recommend you to upgrade!

Resources