Label data points for cumulative plot with Gnuplot - plot

It is straightforward to label data points in Gnuplot, in this example, I use the third column as labels for this data set (data.txt):
1 -22 "Event 0"
2 -139.7 "Event 3"
3 -11 "Event 7"
4 -35.2 "Event 6"
5 -139.7 "Event 2"
6 -139.7 "Event 4"
7 -84.7 "Event 1"
8 -22 "Event 9"
9 -64.9 "Event 8"
10 -38.5 "Event 5"
gnuplot> plot 'data.txt' u 1:2, "" u 1:2:3 w labels rotate offset 1
This is the result (I omitted polishing for this purpose):
However, I need the data points plotted by cumulative sum:
gnuplot> plot 'data.txt' u 1:2 smooth cumulative
Now, how can I label the points at their new "coordinates"? Something like this does not work (I want the labels down in each knee of the cumulative curve):
gnuplot> plot 'data.txt' u 1:2 s cum, "" u 1:2:3 s cum w labels offset 1
The result should look something like this (here manually cut and positioned with Gimp):

You can plot your cumulative graph to a file, and then use those modified data as you would with a regular data file. To access the labels to can use the paste command and make use of extra columns:
set table "cumulative_labels"
plot 'data.txt' u 1:2:3 smooth cumulative w labels
set table "cumulative_data"
plot 'data.txt' u 1:2 smooth cumulative
unset table
plot 'cumulative_data' u 1:2 w l, \
"< paste cumulative_labels cumulative_data" u 4:5:3 w labels offset 1
Edit:
gnuplot-only way to do this, with no intermediate files, but dropping the smooth cumulative option:
sum = 0.
plot "data.txt" u 1:2 s cum, "" u (sum = sum + $2, $1):(sum):3 w labels offset 1

Related

How choose which column put on axis like label?

I have a csv file like this:
10557,1925080,1236052,1210752,1182492
11254,3159084,2264460,2187584,2144416
11334,2348036,1540692,1504536,1458332
11456,1607704,993228,974676,960308
.....
I want create a chart with these data. I want use the first column as x-axes label, and put all other column like different line inside the chart. how can I do it?
This is my code
set terminal pngcairo enhanced font "arial,10" fontscale 2.0 size 1680, 1024
set size 1,1
set ylabel '[y]'
set xlabel '[FIRST COLUMN FROM CSV]'
set datafile separator ","
set autoscale fix
set key top left
set key box
set output 'Figure1.png'
plot \
"figure1.csv" using 2 w l linewidth 3 lc rgb "black" title "second colum", \
"figure1.csv" using 3 w l linewidth 3 lc rgb "black" title "third colum", \
"figure1.csv" using 4 w l linewidth 3 dashtype 2 title "fourth colum", \
"figure1.csv" using 5 w l linewidth 3 dashtype 5 title "fifth colum"
To get evenly spaced tics on the x-axis which get labelled with the values from the first column use xticlabels:
plot "figure.csv" using 0:2:xticlabels(1)

how to improve the following gnu plot?

I have the following gnu plot:
# automobile_input.txt
#
set term png
set output "automobile.png"
#
# Fields in each record are separated by commas.
#
set datafile separator ","
set title "Price versus Curb weight"
set xlabel "Price in dollars"
set ylabel "Curb weight in pounds"
set grid
plot 'x' using 1:2
quit
x is a file containing numbers such as
1,2
0.5,4
etc.
I would like to make a few changes to this plot.
At the top of the plot there is "x using 1:2" and I would like to remove that.
Finally, the most important thing: I would like to add another file, y, in the same format, which will be also plotted on the same plot, only with a different sign and color (instead of pluses in red), for example, blue triangles. I would rather also the pluses be circles.
Omit the data series title by using notitle in your plot line. Adding another curve would be done like this:
plot 'x' using 1:2 notitle, \
'y' using 1:2 notitle
The data series points will adjust automagically. To manually specify the format, you might plot with something like this:
plot 'x' using 1:2 with points pointtype 6 linecolor rgb 'red' title "Data X", \
'y' using 1:2 with points pointtype 8 linecolor rgb 'blue' title "Data Y"
You'll usually see scripts online that abbreviate these command to look like:
plot 'x' w p pt 6 lc rgb 'red' title "Data X", \
'y' w p pt 8 lc rgb 'blue' title "Data Y"

Make error bar to a converted value

Im trying to make errorbars to a already converted value. I have value in the dat file as uk gallons per minute and have now converted it into m^3/min.
My problem is that i cannot get my error bars when i also convert the value. Initially i just bracket the converting and then the accuracy on 0.0025(0.25%) but no error bars appear..
set yrange [34:37.5]
set xlabel "Time [min]"
set ylabel "Flow [m^3/min]"
plot '2015 08 30 0000 Pelletizer Feed (Wide).dat' every ::2372::2459 using 4:($17*0.161) w l lc rgb 'green' title "Run 1", \
'' every ::2372::2459 using 4:17:(($17*0.161)*0.0025) w errorbar lc rgb 'green' notitle, \
'2015 08 30 0000 Pelletizer Feed (Wide).dat' every ::2498::2565 using 4:($17*0.161) w l lc rgb 'blue' title "Run 2", \
'' every ::2498::2565 using 4:17:(($17*0.161)*0.0025) w errorbar lc rgb 'blue' notitle, \
35.42 title "SP" with lines linestyle 2
When plotting with lines and with errorbars you are using different y-values. You have using 4:($17*0.161) for the lines, but using 4:17:(($17*0.161)*0.0025) for the errorbars, so that the errorbars are out of your yrange. Try:
set yrange [34:37.5]
set xlabel "Time (min)"
set ylabel "Flow (m^3/min)"
file = '2015 08 30 0000 Pelletizer Feed (Wide).dat'
set linetype 1 lc rgb 'green'
plot file every ::2372::2459 using 4:($17*0.161) w l lt 1 title "Run 1", \
'' every ::2372::2459 using 4:($17*0.161):(($17*0.161)*0.0025) w errorbar lt 1 notitle

Adding error bars using equation in Gnuplot

I have a transducer data where I know I have a sudden accuracy:
My question is: How to add y-errorbars into my existing code?
set xlabel "Time [min]"
set ylabel "Temperature [Celsius]"
plot '150830AW.dat' every ::1188::1231 using 4:52 w l lc rgb 'green' title "Run 1", \
'150830AW.dat' every ::1251::1284 using 4:52 w l lc rgb 'blue' title "Run 2", \
90 title "Standard" with lines linestyle 2
and
set xlabel "Time [min]"
set ylabel "Pressure [MPa]"
plot '2015 08 30 0000 Pelletizer Feed (Wide).dat' every ::2372::2459 using 4:($8*0.006894759086775369) w l lc rgb 'green' title "Run 1", \
'2015 08 30 0000 Pelletizer Feed (Wide).dat' every ::2498::2565 using 4:($8*0.006894759086775369) w l lc rgb 'blue' title "Run 2"
Have a look at these demos: errorbars. Basically you need a third column with the error.
Since you have 0.5% accuracy on Pressure, you'll have to multiply the pressure column by 0.005 so that your using 4:52 will become using 4:52:($52*0.005).
To activate the errorbar you need to replace the w l (i.e. with lines) with with errorbars.
If you want both the line and errorbars you have to keep your line and add this new line, e.g:
plot '150830AW.dat' every ::1188::1231 using 4:52 w l lc rgb 'green' title "Run 1", \
'' every ::1188::1231 using 4:52:($52*0.005) w errorbar lc rgb 'green' notitle, \
'150830AW.dat' every ::1251::1284 using 4:52 w l lc rgb 'blue' title "Run 2", \
'' every ::1251::1284 using 4:52:($52*0.005) w errorbar lc rgb 'blue' notitle, \
90 title "Standard" with lines linestyle 2
If you want something IMHO nicer, have a look at fill between curves

Is it possible to draw one line per ten lines in gnuplot?

I have data file like following:
#X1 y1 x2 y2 Number
123 567 798 900 1
788 900 87 89 2
....
and I draw my graph using following command
plot '~/Desktop/pointcolor.txt' using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
here is the result.
As you can see in above image, the result is to compressed, so I want to draw one line per ten lines which have same Number in data file.
Edit1:
I try #ewcz solution, as follow:
stat="0 0 0 0 0 0 0" # How should I define array as [gnuplot][2] didn't support it?
plot "< awk '{if(( (stat[$5]++)%10==0 )) print}'~/Desktop/pointt.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
but I get this error:
gnuplot> load "gnuplot.cmd"
awk: line 1: syntax error at or near
gnuplot> plot "< awk '{if(( (stat[$5]++)%10==0 )) print}'~/Desktop/pointcolor.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
^
"gnuplot.cmd", line 6: warning: Skipping data file with no valid points
gnuplot> plot "< awk '{if(( (stat[$5]++)%10==0 )) print}'~/Desktop/pointcolor.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
^
"gnuplot.cmd", line 6: x range is invalid
Edit2:
The solution:
plot "< awk '{if((stat[$5]++)%10==0) print}' ~/Desktop/pointt.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
In order to achieve this, one has to use (most likely) some kind of preprocessing of the input. Fortunately, Gnuplot allows to plot a result of a command in a straightforward way. In your case, one could modify the plot command as:
plot "< gawk '{if((stat[$5]++)%10==0) print;}' ~/Desktop/pointcolor.txt" ...
Here, the id of the row (based on the fifth column) is stored in an array stat. If this id is divisible by 10, the row is printed and thus consequently plotted (i.e., other input rows are discarded).

Resources