Combining acspline with filledcurve on data - gnuplot

I know how to use filledcurve with using 1:2:3 to fill the area between the curves described by columns 2 and 3.
I also know how to smooth a single curve using acsplines with using 1:2:(0.1) (with 0.1 being the smoothing weight for each point).
But I fail to combine the two, i.e. fill the area between two smoothed curves. All variants I try give me error messages like duplicated or contradicting arguments in datafile options.
This is what I tried:
plot 'datafile' using 1:2:3:(0.1):(0.1) smooth acs with lines
plot 'datafile' using 1:2:(0.1):3:(0.1) smooth acs with lines
Is this combination possible at all? How is the syntax then?

I guess you can't combine smooth acspline and with filledcurves, but I also don't know why this shouldn't be possible.
Well, as a workaround, plot your smooth acspline curve into a data table first and then plot it with filledcurves.
Code:
### filled acspline curve
reset session
$Data <<EOD
1 2
2 4
3 3
4 1
EOD
# plot your acspline data into a table
set table $ACSpline
plot $Data u 1:2 smooth acspline
unset table
set style fill transparent solid 0.1
plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Original data", \
$Data u 1:2 smooth acspline lw 2 lc rgb "red" ti "acspline", \
$ACSpline u 1:2 w filledcurves x1 lc rgb "red" ti "acspline filled"
### end of code
Result:
Addition:
There is another way to get data into a table. Check help set print.
With this, you can get the data of the two splines into one datablock and can plot the area between them. Maybe someone knows a simpler way to achieve this.
Code:
### filled curve between two acsplines
reset session
$Data <<EOD
1 2 4
2 4 1
3 3 0
4 1 3
EOD
# plot your acspline data into tables
set table $ACSpline1
plot $Data u 1:2:(1) smooth acspline
unset table
set table $ACSpline2
plot $Data u 1:3:(1) smooth acspline
unset table
set print $BetweenSplines
do for [i=1:|$ACSpline1|] {
print sprintf("%s %s %s",word($ACSpline1[i],1),word($ACSpline1[i],2),word($ACSpline2[i],2))
}
set print
set style fill transparent solid 0.5
plot $Data u 1:2 w lp pt 7 lc rgb "black" ti "Original data col 2", \
$Data u 1:3 w lp pt 7 lc rgb "blue" ti "Original data col 3", \
$ACSpline1 u 1:2 w l lw 2 lc rgb "red" ti "acspline col 2", \
$ACSpline2 u 1:2 w l lw 2 lc rgb "green" ti "acspline col 3", \
$BetweenSplines u 1:2:3 w filledcurves lc rgb "yellow" ti "acspline filled"
### end of code
Result:

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:

How do I add more space using gnuplot yerrorbars when I have a lot of data on my chart?

I added the yerrorbars keyword to show the standard deviation on my chart but because I have a lot of data the plot is not very clear and the std deviation as well. I would like to add more spaces when showing the standard deviation in the same way that is added on the line style using pi : set style line 4 lc rgb '#000000' lt 3 lw 1.5 ps 0.5 pt 3 pi 15. How would I do that?
set label 1 "(a) workload: 50K r/s\npre-agg 77K tuples" at "300",6.5 font "{,10}"
plot t=0 "throughput-vs-latency-50K-8combiners-8reducers-all.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(2)/1000):(column(3)/1000) skip 2 notitle with linespoints ls 1 axis x1y1 \
, t=0 "throughput-vs-latency-50K-8combiners-8reducers-all.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(4)/1000) skip 2 notitle with linespoints ls 2 axis x1y1 \
, t=0 "throughput-vs-latency-50K-8combiners-8reducers-all.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(6)/1000) skip 2 notitle with linespoints ls 3 axis x1y2 \
, t=0 "throughput-vs-latency-50K-8combiners-8reducers-all.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(8)/1000):(column(9)/1000) skip 2 notitle with yerrorbars ls 4 axis x1y2 \
I think you would have to split the curve for that data into two parts.
The first part would draw the lines and points for every point in the data set;
the second part would draw errorbars only for every Nth point. The keyword needed is every N.
set errorbars lt -1
plot $DATA using 1:2 with linespoints lt 3 notitle, \
$DATA every 5 using 1:2:3 with yerrorbars lt 3 title "DATA"
Another suggestion: instead of crowded errorbars, why not an "error-shade"?
Code:
### shaded area as error "bar"
reset session
# create some test data
set table $Data
plot '+' u 1:(sin($1)):(rand(0)+0.25) w table
unset table
set key invert
plot $Data u 1:($2-$3):($2+$3) with filledcurves lc rgb "light-grey" ti "Error", \
'' u 1:2 w lp ti "Data"
### end of code#
Result:
For many data points with errorbars, consider set bar 0, error bars in the background, and/or transparency. Also point size can be reduced.
set samp 2000
set table $Data
plot '+' u 1:(sin($1)+(rand(0)+0.25)):(rand(0)+0.25) w table
unset table
set bar 0
plot $Data with err lc rgb "grey" ti "Error", \
'' u 1:2 w p lc "black" pt 6 ti "Data"

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

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