gnuplot 5.5: no auto axis limits - gnuplot

I've installed gnuplot 5.5 from git. Now it doesn't plot with automatic axis limits.
Here is the graph produced with earlier version (5.3 or 5.4):
And this is plotted with current version:
Here is the command for this plot:
plot [][3.0145:3.5755] 3.04 w filledcurves x1 fc rgb "#d9d9d9" notitle, \
3.55 w filledcurves x2 fc rgb "#d9d9d9" notitle, \
for [i=1:11] 'gpdata.dat' every :::0::0 using 1:i+1 lt i+1 lw 3 ps 1.5 t word(elements,i) w linesp,\
3.04 w lines lw 4 lt 1 lc rgb "red" t 'Допуск',3.55 w lines lw 4 lt 1 lc rgb "red" notitle
When I set the limits explicitly: plot [:35064.46][3.0145:3.5755] I get this:
i.e. the end points are hidden.
Is there a way to return previous behavior?

According to the StackOverflow "rules": no answer in the comments...
set xrange[:] noextend
should avoid the extension of the plotting range to the next "nice" tic. Check help noextend.

Related

Fill colour between two smooth lines drawn by data points in gnuplot

I have file “data.txt” containing three columns. Column 1 is for x axis. I want to draw smooth curves corresponding to data points of column 2 and 3 and then want to fill colour between these two lines.
File content is;
10 -1.3 1.1
20 -0.956 0.933
50 -0.761 0.684
80 -0.523 0.439
110 -0.227 0.20
130 -0.07 0.06
My script lines are,
plot “data.txt” u 1:2 smooth bezier w filledcurves above,\
“data.txt” u 1:3 smooth bezier w filledcurves below
But I’m not getting desired shaded plot.
I guess you have two challenges here:
you cannot smooth and fill at the same time
you can only fill between two columns of the same dataset or file
One possible way would be the following:
plot the data smooth bezier into a table $Smooth
N is the number of lines the combined smoothed data $Smooth
merge these smoothed data by using line 1 and 1+N/2, line 2 and 2+N/2, etc. into a dataset $Paste
for the fill you then have to use columns 1, 2 and 5
Script:
### fill area between smoothed curves
reset session
$Data <<EOD
0 0 90
10 10 50
50 20 40
80 50 60
100 30 50
EOD
set table $Smooth
set samples 20
plot $Data u 1:2 smooth bezier
plot $Data u 1:3 smooth bezier
unset table
set print $Paste
N = |$Smooth|
do for [i=1:N/2] {
print $Smooth[i].$Smooth[i+N/2]
}
set print
plot $Data u 1:2:3 w filledcurves lc rgb 0xcc0000ff ti "fill between data", \
'' u 1:2 w lp pt 7 lc "red" ti "original data", \
'' u 1:3 w lp pt 7 lc "red" notitle, \
$Smooth u 1:2 w lp pt 7 lc "green" ti "smoothed curves", \
$Paste u 1:2:5 w filledcurves lc rgb 0xccff0000 ti "fill between smoothed"
### end of script
Result:
For future reference, the development version of gnuplot (5.5) greatly extends the options for smoothing. For your case the obvious command works as expected. The only caveat is that for open curves (endpoints are not equal) you must use smooth sbezier rather than smooth bezier.
$DATA << EOD
10 -1.3 1.1
20 -0.956 0.933
50 -0.761 0.684
80 -0.523 0.439
110 -0.227 0.20
130 -0.07 0.06
EOD
set xrange noextend
set style fill transparent solid 0.25
plot $DATA using 1:2:3 smooth sbezier with filledcurves between, \
'' using 1:2 with lp, '' using 1:3 with lp
As far as I understand, above and below expect three column input, and this does not work with smooth.
But starting from this and this answer, you can try something like the following:
set xzeroaxis
set tics front
plot "data.txt" u 1:3 smooth bezier notitle w filledcurves x1 lc rgb "#b0ffff00", \
"data.txt" u 1:2 smooth bezier notitle w filledcurves x1 lc rgb "#00ffffff", \
"data.txt" u 1:3 smooth bezier lt 1, \
"data.txt" u 1:2 smooth bezier lt 2
Both filledcurves plots reach from the curve to the x-axis, the second one in white covers the first one in yellow leaving the space between the two curves in yellow.
See help lc or help linecolor for color details.
This is the 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

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 - calculate distance between lines

Can gnuplot calculate the distance between two lines or maybe two points?
I'm having a plot where two (main) lines are plotted. For the moment let's assume that the first line is always above the second one. Is there a way to calculate the distance from line 2 to line 1 at a given x-value?
here is a picture of what my plot looks like and which distance I want to calculate:
The vertical lines are just for style and have nothing to do with the actual plot, their data is stored in test.dat and test2.dat.
My data-files of the lines look like this:
line1
0 118.1
2.754 117.77
4.054 117.64
6.131 116.17
7.7 116.04
8.391 115.36
10.535 115.25
11.433 116.03
12.591 116.22
19.519 118.59
line2
19.4 118.51
15.2 116.56
10.9 115.94
10.35 114.93
9.05 114.92
8.3 115.9
5.9 116.19
4.2 116.62
2.2 117.66
-0.3 118.06
My plotting-code looks like this:
set term wxt enhanced
cd 'working directory'
unset key
set size 0.9,0.9
set origin 0.1,0.1
set title 'TITLE'
unset border
set label 21 " rotate by 45" at -3.0,0.0 rotate by 45 point ps 2
set xrange [0:19.519]
set yrange [110:119]
set xtics nomirror(0, 2.745, 4.054, 6.131, 7.7, 8.391, 10.535, 11.433, 12.591, 19.519) rotate by 90 offset 0,-0.1 right
set ytics " ", 30000
plot "line1.dat" using ($1):($2):2 with labels offset 1, 1.8 rotate by 90, "line1.dat" using 1:2 with lines lt 1 lw 1 lc rgb '#000000', +112 lt 1 lw 1 lc rgb '#000000' , 'test.dat' with lines lt 1 lw 1 lc rgb '#000000', +110 lt 1 lw 1 lc rgb '#000000', 'line2.dat' with lines lt 0.5 lw 1 lc rgb '#000000', 'test2.dat' with lines lt 0.5 lw 1 lc rgb '#000000'
You can measure the distance manually. Move the mouse to the first point and type 'r'. Then as you move the mouse around, the x and y offsets, distance and angle are displayed. Type '5' to draw a line segment and to toggle between degrees and tangent display. Zooming in beforehand increases accuracy.
By the way, typing 'h' in the plot window will display a list of keybindings to the console.
An answer to this "rather old" question still might be of interest to OP, if not, maybe to others.
Yes, you can calculate and plot the difference of two lines. It requires some linear interpolation. Simply assign the desired x-value to the variable myX.
Data:
SO17717287_1.dat
0 118.1
2.754 117.77
4.054 117.64
6.131 116.17
7.7 116.04
8.391 115.36
10.535 115.25
11.433 116.03
12.591 116.22
19.519 118.59
SO17717287_2.dat
19.4 118.51
15.2 116.56
10.9 115.94
10.35 114.93
9.05 114.92
8.3 115.9
5.9 116.19
4.2 116.62
2.2 117.66
-0.3 118.06
Script: (works for gnuplot>=4.6.0)
### calculating and plotting a difference between two curves
reset
FILE1 = "SO17717287_1.dat"
FILE2 = "SO17717287_2.dat"
set border 1
unset key
set origin 0.05,0.05
set size 0.9,0.8
set xrange [0:19.519]
set xtics nomirror rotate by 90 offset 0,-0.1 right
set yrange [110:119]
unset ytics
myX = 15.2
getYa(xi) = (x0=x1, x1=$1, y0=y1, y1=$2, x1==xi ? ya=y1 : (sgn(x0-xi)!=sgn(x1-xi)) ? ya=(y1-y0)/(x1-x0)*(xi-x0)+y0 : NaN)
getYb(xi) = (x0=x1, x1=$1, y0=y1, y1=$2, x1==xi ? yb=y1 : (sgn(x0-xi)!=sgn(x1-xi)) ? yb=(y1-y0)/(x1-x0)*(xi-x0)+y0 : NaN)
set samples 2 # set to minimal possible value for plotting '+'
plot x1=y1=NaN FILE1 u 1:2:2:xtic(1) w labels offset 0,0.5 left rotate by 90, \
'' u 1:(getYa(myX),$2) w l lc rgb 'black', \
'' u 1:2:(0):(110-$2) w vec lt 0 nohead, \
+112 w l lc rgb 'black', \
x1=y1=NaN FILE2 u 1:(getYb(myX),$2) w l lt 0 lc rgb 'black', \
'+' u (myX):(ya):(0):(yb-ya) w vec heads lc rgb "red", \
'+' u (myX):(ya):(sprintf("%.3f",yb-ya)):xtic(sprintf("%g",myX)) w labels tc rgb "red" offset 0,1, \
'+' u (myX):(ya):(0):(110-ya) w vec nohead lt 0 lc rgb "red"
### end of script
Result: (created with gnuplot 4.6.0)

Thicker lines in the legend of gnuplot

I'm plotting some data curves with gnuplot, and they look like this:
However, the line samples in the legend are too thin. When you have more curves, it becomes hard to distinguish the colors. You can increase the thickness of the curves using "linewidth", e.g., by adding "lw 3" to the plot command, and you'd get this:
However, this increases the thickness everywhere. Is it possible to make the lines thick in the legend only? I know it can be done "the other way", by postprocessing on the output .png file. But is there a direct approach, using some gnuplot setting/wizardry?
Unfortunately, I don't know a way to control the thickness of the lines in the key, since they correspond to the lines being drawn. You can see what you can change by typing help set key in gnuplot.
Using multiplot, you can draw the plot lines first without the key, then draw the key again for 'ghost lines'. Here is a code sample which would do that:
set terminal png color size 800,600
set output 'plot.png'
set multiplot
unset key
plot '../batteries/9v/carrefour.txt' w lp, \
'../batteries/9v/philips.txt' w lp, \
'../batteries/9v/sony.txt' w lp
set key; unset tics; unset border; unset xlabel; unset ylabel
plot [][0:1] 2 title 'Carrefour' lw 4, \
2 title 'Philips' lw 4, \
2 title 'Sony' lw 4
In the second plot command, the function 2 (a constant) is being plotted with a y range of 0 to 1, so it doesn't show up.
I ran across this post and it gave me a critical idea.
The provided solution does not work in multiplot mode, since the second plot command will trigger the second plot, which is most likely not desired.
as a workaround one can set the original data as "notitle", then plot data outside of range with the same linetype and color in different thickness with the desired title. I'll just leave my current example here. It also includes linestyles that i have declared. So i just use the same linestyle (ls) to get the same color but change the thickness on the second line.
# for pngs
set terminal pngcairo size 1600,600 font ',18' enhanced
set output "pic_multi_kenngr_ana.png
set style line 2 lc rgb '#0ce90b' lt 1 lw 1.5 # --- green
set style line 3 lc rgb '#09e0b3' lt 1 lw 1.5 # .
set style line 4 lc rgb '#065fd8' lt 1 lw 1.5 # .
set style line 5 lc rgb '#4e04cf' lt 1 lw 1.5 # .
set style line 6 lc rgb '#c702a9' lt 1 lw 1.5 # .
set style line 7 lc rgb '#bf000a' lt 1 lw 1.5 # --- red
set multiplot layout 1,2
set xtics rotate
set tmargin 5
set xtics 12
set grid xtics
# set axis labels
set ylabel 'T [K]'
set xlabel 'Zeit [h]'
# select range
set xrange [0:48]
set yrange [290.15:306.15]
set title "(a) Bodentemperatur"
set key top right Right
plot 'par_crank_hom01lvls.04.dat' u 1:3 with lines ls 7 notitle,\
'par_crank_str01lvls.16.dat' u 1:3 with lines ls 2 notitle,\
500 t 'z = 4 cm' ls 7 lw 4,\
500 t 'z = 16 cm' ls 2 lw 4
################################################
set title "(b) Bodenwärmestrom an der Oberfläche"
set ylabel 'G [W m^{-2}]'
set yrange[-110:110]
unset key
plot 'par_crank_str01_ghf.dat' u 1:3 with lines
unset multiplot
I hope this will help someone
An even more simple work-around (imho) is to define the colours explicitly and plot each line twice, once with high lw for the key and also with the title to appear in the key, but adding "every ::0::0" which effectively ends up in plotting nothing, and once the normal way. See the following code snippet:
plot data u 0:1 w l linecolor rgb #1b9e77 lw 2 t "",\
data every ::0::0 u 0:1 w l linecolor rgb #1b9e77 lw 4 t "Title"
To expand on the NaN comment by #Svalorzen, the following will graph two lines of width 1 from some datafile.txt with no titles and create matching blank lines with the specified titles and width 5 for the key only:
plot [][]\
NaN title "Title1" w line lt 1 lc 1 lw 5,\
NaN title "Title2" w line lt 1 lc 2 lw 5,\
"datafile.txt" using 1:2 title "" w line lt 1 lc 1 lw 1,\
"datafile.txt" using 1:3 title "" w line lt 1 lc 2 lw 1
I find an answer for this:
Set key linewidth
in your case, must be:
plot '../batteries/9v/carrefour.txt' w l lw 1 linetype 1 notitle, 0/0 linetype 1 linewidth 5 title 'Carrefour'
rep '../batteries/9v/philips.txt' w l lw 1 linetype 2 notitle, 0/0 linetype 2 linewidth 5 title 'Philips'
rep '../batteries/9v/sony.txt' w l lw 1, linetype 3 notitle, 0/0 linetype 3 linewidth 5 title 'Sony'
Try something like:
plot # ... \
keyentry w l lw 1 lc 2 t "Title" # ...
And remove the old keys.

Resources