GNUPLOT : how to stop "histeps" from terminating to zero (y=0) at start and endpoints? - gnuplot

I am using the following script for plotting data points from file "delete.dat"
set terminal jpeg
set output "delete_histeps.jpeg"
set title "with histeps"
plot "delete.dat" using 1:2 index 0 pt 7 ps 0.2 lc "black" notitle,\
"delete.dat" using 1:2 index 1 pt 7 ps 0.2 lc "red" notitle,\
"delete.dat" using 1:2 index 2 pt 7 ps 0.2 lc "green" notitle,\
"delete.dat" using 1:2 index 0 with histeps lc "black",\
"delete.dat" using 1:2 index 1 with histeps lc "red",\
"delete.dat" using 1:2 index 2 with histeps lc "green"
and the "delete.dat" file is
1 2
3 4
5 6
7 8
9 10
-1 5
-2 3
-3 4
-4 2
-5 6
5 1
6 2
7 3
8 4
9 5
10 4
11 3
12 12
But the start and end step is dropping to zero, which I don't want. Though for step and fsteps command, the steps begin (end) at the first (last) data point, without dropping down to zero (y=0). Can you please suggest that works like histeps (which keeps data points in the middle of the steps) but does not terminate to zero (like steps or fsteps). I'm also attaching pictures.

If your data points are equidistant (like the ones you provided), an alternative hack would be possible as well by combining fsteps and steps and shifting the x-value by half the point-to-point-distance:
plot "delete.dat" i 0 pt 7 ps 2 lc "black" not, \
'' i 1 pt 7 ps 2 lc "red" not, \
'' i 2 pt 7 ps 2 lc "green" not, \
'' u ($1-1.0):2 i 0 w steps lc "black", '' u ($1+1.0):2 i 0 w fsteps lc "black" not, \
'' u ($1+0.5):2 i 1 w steps lc "red", '' u ($1-0.5):2 i 1 w fsteps lc "red" not, \
'' u ($1-0.5):2 i 2 w steps lc "green", '' u ($1+0.5):2 i 2 w fsteps lc "green" not
The trick here is that steps or fsteps alone would miss either the last or the first point and the line would end in mid-air, therefore both have to be plotted on top of each other with the same plotting style.
One must take care of the correct sign: if x is positive, steps get a downshift and fsteps get an upshift; and vice-versa if x is negative.
My answer is definitely not as "robust" as the one of theozh, but maybe easier to understand.

Well, that's how hispteps, steps, and fsteps have been defined.
Then, you have to create your own steps. A solution could be the following:
Code: (improved version)
### steps like histeps but not dropping to zero
reset session
set colorsequence classic
$Data <<EOD
1 2
3 4
5 6
7 8
9 10
-1 5
-2 3
-3 4
-4 2
-5 6
5 1
6 2
7 3
8 4
9 5
10 4
11 3
12 12
EOD
set table $myStep
do for [i=0:2] {
plot $Data u ($0==0?(x1=x2=$1):(x1=x2,x2=$1),(c=$0,x1+x2)/2.):2 index i w table
plot $Data u 1:2 every ::c index i w table # add last value
plot '+' u ("") every ::::1 w table # add two empty lines
}
unset table
set key top left
plot for [i=0:2] $myStep u 1:2 index i w step lc i lw 3 notitle,\
for [i=0:2] $Data u 1:2 index i w p pt 7 lc i notitle, \
### end of code
Result:

Related

How to plot only max values for yerrorbars in Gnuplot?

I have this plot where I show the average values and the standard deviation. The problem is that there is a high +/- error on some lines and I would like to show only the max values for the standard deviation. So the plot can be more clear. Now I am using linespoints and yerrorbars and the plot looks like below:
As you can see the orange and green lines vary a lot. I would like to show only the max values for them so the plot becomes more clear. The script that I am using is below:
plot \
t=0 "throughput-vs-networkbuffer-500K-8reducers-all.csv" every 30 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(8)) skip 2 notitle "no pre-agg" with linespoints lc rgb '#E02F44' lt 1 lw 1.0 ps 0.7 pt 2 pi 30 axis x1y1 \
,t=0 "throughput-vs-networkbuffer-500K-8reducers-all.csv" every 30 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(8)):(column(9)) skip 2 title "no pre-agg" with yerrorbars lc rgb '#E02F44' lt 1 lw 1.0 ps 0.7 pt 2 pi 30 axis x1y1 \
,t=0 "netBuffer-20K-200K-20K-8local-8global-onephase-all.csv" every 28 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(2)) skip 2 notitle "local mini-batch" with linespoints lc rgb '#008000' lt 1 lw 1.0 ps 0.6 pt 6 pi 28 axis x1y1 \
,t=0 "netBuffer-20K-200K-20K-8local-8global-onephase-all.csv" every 28 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(2)):(column(3)) skip 2 title "local mini-batch" with yerrorbars lc rgb '#008000' lt 1 lw 1.0 ps 0.6 pt 6 pi 28 axis x1y1 \
,t=0 "netBuffer-20K-200K-20K-8local-8global-twophase-all.csv" every 26 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(2)) skip 2 notitle "local agg 2-phases" with linespoints lc rgb '#FF780A' lt 1 lw 1.0 ps 0.6 pt 8 pi 26 axis x1y1 \
,t=0 "netBuffer-20K-200K-20K-8local-8global-twophase-all.csv" every 26 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(2)):(column(3)) skip 2 title "local agg 2-phases" with yerrorbars lc rgb '#FF780A' lt 1 lw 1.0 ps 0.6 pt 8 pi 26 axis x1y1 \
,t=0 "netBuffer-vs-latency-20K-200K-20K-8adcom-8reducers-all.csv" every 24 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(4)) skip 2 notitle "AdCom pre-agg" with linespoints lc rgb '#3274D9' lt 1 lw 1.0 ps 0.6 pt 5 pi 24 axis x1y1 \
,t=0 "netBuffer-vs-latency-20K-200K-20K-8adcom-8reducers-all.csv" every 24 u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(4)):(column(3)) skip 2 title "AdCom pre-agg" with yerrorbars lc rgb '#3274D9' lt 1 lw 1.0 ps 0.6 pt 5 pi 24 axis x1y1 \
I improved it by adding 4 columns where the third is only the average and the fourth is the average + the standard deviation:
X:(column(2)):(column(2)):(column(2) + column(3))
However, if there is a way more elegant to do it I appreciate any help!
Here is a minimal example for half an error bar using with vectors and set style arrow.
Although, I'm not sure whether it is "experimentally acceptable" to just display "half" an error bar.
Code:
### "half" yerrorbars
reset session
$Data <<EOD
# x y yerr
1 0.10 0.05
2 0.20 0.10
3 0.45 0.21
4 0.67 0.28
5 0.44 0.11
EOD
unset key
set xrange[0:6]
set style arrow 1 size 0.1,90 lc "red"
plot $Data u 1:2 w lp pt 7, \
'' u 1:2:(0):3 w vectors as 1
### end of code
Result:

categorising points by using of gnuplot

I am going to plot a file containing 4 columns. first and second column are x and y respectively. I want to categorize these point based on the third and fourth column. In fact, the third column should display the color (red or blue) of point and the fourth column should determine its type (square or circle ). how could I reach to this goal by gnu-plot?
I should mention that I tried this, by it does not work!
set style line 1 lc rgb 'red' pt 7
set style line 2 lc rgb 'red' pt 7
set style line 3 lc rgb 'blue' pt 9
set style line 4 lc rgb 'blue' pt 9
plot 'data' w ($3= 1 && $4= 1) ? p ls 1 \
: ($3= 1 && $4= 2) ? p ls 2 \
: ($3= 2 && $4= 1) ? p ls 3 \
: ($3= 2 && $4= 2) ? p ls 4
Please check help points. From the manual:
plot DATA using x:y:pointsize:pointtype:color \
with points lc variable pt variable ps variable
You don't show sample data. If you can adjust your data, the easiest would be the following below.
If you want to set the color by name in your file, check this.
Code:
### variable pointtype and color
reset session
$Data <<EOD
1 2 5 0xff0000
3 4 7 0xff0000
5 6 5 0x0000ff
7 8 7 0x0000ff
EOD
plot $Data u 1:2:3:4 w p ps 5 pt var lc rgb var
### end of code
Result:

how to define X's label on gnuplot

This is My data :
18_AGT_s 8234.00 8234.00 8234.00
18_MAC_s 8414.36 8308.36 8246.33
9_MAC_r 8414.36 8308.36 8246.33
9_MAC_s 8414.55 8309.55 8246.45
8_MAC_r 8414.55 8309.55 8246.45
8_MAC_s 8414.56 8310.08 8246.47
6_MAC_r 8414.56 8310.08 8246.47
6_MAC_s 8416.19 8310.21 8246.49
1_MAC_r 8416.19 8310.21 8246.49
and here is my gnuplot code :
plot "dat" using ($0+1):2 with linespoints pt 8 ps 2 lt 2 lw 4 lc rgb
"green" title "DMSR","dat" using ($0+1):3 with linespoints pt 5 ps 2
lt 3 lw 4 lc rgb "blue" title "Alarm","dat" using ($0+1):4 with
linespoints pt 6 ps 2 lt 4 lw 4 lc rgb "red" title "Emergency"
and here is my out put :
But In the step part I want to have 18_AGT_s and 18_MAC_s and 9_MAC_s and .... for example on the X part I want to have 18_AGT_s in stand of 1 or I want to have 18_MAC_2 instand of 2 and 9_MAC_r instand of 3 etc. Any help thanks
Use the xticlabels() option with the column number with the labels as argument (1, in this case):
# Optionally rotate labels so they fit
set xtics rotate
plot "dat" using ($0+1):2 with linespoints pt 8 ps 2 lt 2 lw 4 lc rgb \
"green" title "DMSR","dat" using ($0+1):3 with linespoints pt 5 ps 2 \
lt 3 lw 4 lc rgb "blue" title "Alarm","dat" using \
($0+1):4:xticlabels(1) with linespoints pt 6 ps 2 lt 4 lw 4 lc rgb \
"red" title "Emergency"
Here you only need to use it for the last plot instance so that it overwrites the number options.

Plot with shaded regions between lines

I have the 2 files from either of them I'll plot a point line using the following code:
set terminal postscript eps color solid font "Helvetica, 22"
set size ratio 0.625
set output "example.eps"
set key right top
plot "traffic.txt" using 1:2 title "traffic" with lp pt 7 ps 1 lc rgb "red", \
"solar.txt" using 1:($2*100) title "solar" with lp pt 9 ps 1 lc rgb "blue"
Either line forms a region together with x axis and the regions formed by both lines overlaps. I was wondering how may I shade the overlapping parts.
Thanks!
(The files used are as follows)
File 1
1 66.660000
2 47.830000
3 39.270000
4 27.940000
5 24.990000
6 27.930000
7 32.060000
8 43.650000
9 70.470000
10 73.430000
11 87.690000
12 111.790000
13 122.170000
14 114.930000
15 111.620000
16 109.330000
17 121.370000
18 118.600000
19 132.890000
20 132.480000
21 148.360000
22 152.260000
23 140.510000
24 99.120000
File 2
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0.121933
10 1.81455
11 2.25622
12 2.67994
13 2.87834
14 2.53149
15 1.29541
16 0.57571
17 0.0883007
18 0
19 0
20 0
21 0
22 0
23 0
24 0
You can use the filledcurves plotting style. For that all data must be contained in one file. You can combine the files on-the-fly e.g. with paste. For a platform-independent solution with python look e.g. this answer.
With filledcurves you can also distinguish between above and below in order to use different colors:
set key right top
set autoscale xfix
set xtics 4
plot "< paste traffic.txt solar.txt" using 1:2:($4*100) with filledcurves below lc rgb "#ffaaaa" t '', \
"" using 1:2:($4*100) with filledcurves above lc rgb "#aaaaff" t '',\
"traffic.txt" using 1:2 title "traffic" with lp pt 7 ps 1 lc rgb "red", \
"solar.txt" using 1:($2*100) title "solar" with lp pt 9 ps 1 lc rgb "blue"
The result with 4.6.4 is:
To shade only the region where the two curves overlap, you need a workardound. First shade the region between the narrower curve and the x1 axis, and then overwrite parts of that shading with white:
set autoscale xfix
set xtics 4
plot "< paste traffic.txt solar.txt" using 1:($4*100) with filledcurves x1 lc rgb "#ffaaaa" t '', \
"" using 1:2:($4*100) with filledcurves below lc rgb "white" t '',\
"traffic.txt" using 1:2 title "traffic" with lp pt 7 ps 1 lc rgb "red", \
"solar.txt" using 1:($2*100) title "solar" with lp pt 9 ps 1 lc rgb "blue"
This gives:

Gnuplotting multi-plot data without a textfile

I've just read Gnuplotting data without a textfile, and I want to do the same thing, but with a "multi-plot". I currently have:
plot 'data.csv' using 1:3:2:6:5:7:xticlabels(8) with candlesticks title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4:4 with candlesticks lt -1 notitle
and I want to inline the data in data.csv.
This is easy enough:
set multiplot layout 1,2
plot '-' u 1:2
1 2
2 3
3 4
e
plot '-' u 1:2
2 3
3 4
4 5
e
Note that inline data is not really particularly happy with the '' pseudofile. You would actually need to include your entire data again at that point. So, If you want 2 traces on the same subplot of a multiplot:
set multiplot layout 1,2
plot '-' u 1:2, '-' u 1:3
1 2 3
4 5 6
7 8 9
e
1 2 3
4 5 6
7 8 9
e
plot '-' u 1:($2*$3)
1 2 3
4 5 6
7 8 9
e
This ends up being the same thing as if you had a datafile data.txt:
#data.txt
1 2 3
4 5 6
7 8 9
and plotted it with this (much simpler) script:
set multiplot layout 1,2
plot 'data.txt' u 1:2, '' u 1:3
plot '' u 1:($2*$3)

Resources