How to add value for each points with style line? - linux

I use this script Gnuplot :
set title "df -m command test"
set terminal png truecolor size 720,480 background rgb "#eff1f0"
set output "/xxx/xxx/xxx/test.png"
set grid
set style line 1 \
linecolor rgb '#0060ad' \
linetype 1 linewidth 2 \
pointtype 7 pointsize 1.5
set offsets 0.5,0.5,0,0.5
set datafile separator ","
set ylabel " MB BLOCK "
set xlabel " Date "
set format y "%g"
plot "/xxxx/xxx/xxx/TEST.txt" using 2:xtic(1) with linespoints linestyle 1 title "MB used"
With these data :
2019-08-28,384.00
2019-08-29,394.00
2019-08-30,354.00
2019-08-31,384.00
2019-09-01,484.00
2019-09-02,324.00
2019-09-03,384.00
To create this graph :
(source: noelshack.com)
Can you show me how I can put the value over each point ?

What about this? Also check help labels.
Code:
### plot with values as labels at datapoints
reset session
$Data <<EOD
2019-08-28,384.00
2019-08-29,394.00
2019-08-30,354.00
2019-08-31,384.00
2019-09-01,484.00
2019-09-02,324.00
2019-09-03,384.00
EOD
set datafile separator ","
set offsets 0.5,0.5,20,20
myLabel(n) = sprintf("%g",n)
plot $Data u 2:xtic(1) w lp pt 7 lc rgb "blue" title "MB used", \
$Data u 0:2:(myLabel($2)) w labels offset 0,1.5 notitle
### end of code
Result:

Related

Bashscript with Gnuplot on .csv and timespace

I am trying to extract a string from a csv capture. I am trying to plot labels on the graph.
these are the first few lines (variable amount):
Time,SecExec
26/May/2022:00:08:07,0.666
26/May/2022:00:19:05,0.720
26/May/2022:00:20:33,0.965
26/May/2022:00:28:01,0.662
26/May/2022:00:28:38,1.090
26/May/2022:06:07:41,0.016
26/May/2022:06:09:07,1.194
26/May/2022:06:16:36,0.017
26/May/2022:06:36:37,0.743
26/May/2022:06:56:37,0.737
26/May/2022:07:09:16,0.006
26/May/2022:07:09:16,0.006
26/May/2022:07:10:55,0.009
26/May/2022:07:16:36,0.014
26/May/2022:07:16:39,0.008
26/May/2022:07:18:22,0.696
My execution code:
reset session
N1 = ARG1 #Title
N2 = ARG2 #File name
set datafile separator ','
set xdata time
set timefmt "%d/%m/%Y:%H:%M:%S"
set ylabel "Tiempo" font ",11"
set title N1 font ",14"
set format x "%d/%m/%Y:%H:%M:%S"
set xlabel "Fecha" font ",11"
set boxwidth 2.0 relative
set style fill solid 0.4
set grid x,y
set term png size 1200, 720
set output sprintf("numbers.png")
plot N2 u 1:2 w lp lw 1.5 lc 7
set output
My input in terminal:
gnuplot -c "codedata" "graphic-title" "archic.csv"
If I use this manual in the Gnuplot Terminal, it plots the desired data. The problem is that the execution leaves a range of invalid fields
You are using the wrong time specifier. You should use %b or %B depending if you have abbreviated or full month names. Check help time_specifiers.
Script:
### plot time data with month name
reset session
$Data <<EOD
Time,SecExec
26/May/2022:00:08:07,0.666
26/May/2022:00:19:05,0.720
26/May/2022:00:20:33,0.965
26/May/2022:00:28:01,0.662
26/May/2022:00:28:38,1.090
26/May/2022:06:07:41,0.016
26/May/2022:06:09:07,1.194
26/May/2022:06:16:36,0.017
26/May/2022:06:36:37,0.743
26/May/2022:06:56:37,0.737
26/May/2022:07:09:16,0.006
26/May/2022:07:09:16,0.006
26/May/2022:07:10:55,0.009
26/May/2022:07:16:36,0.014
26/May/2022:07:16:39,0.008
26/May/2022:07:18:22,0.696
EOD
set datafile separator ','
set xdata time
set timefmt "%d/%b/%Y:%H:%M:%S"
set xlabel "Fecha" font ",11"
set format x "%b %d\n%H:%M"
set ylabel "Tiempo" font ",11"
set grid x,y
plot $Data u 1:2 w lp lw 1.5 lc 7
### end of script
Result:

Problem with the starting date and end date on my script gnuplot 4.6

First of all, I'm bound to use the 4.6 version of gnuplot on my server.
I've these data :
2019-10;27.39
2019-11;27.39
2019-12;27.54
2020-01;27.13
2020-02;27.01
2020-03;26.93
2020-04;26.46
2020-05;26.63
And I've this gnuplot script :
reset
FILE = "LINEARFIT.txt"
set datafile separator ";"
set xdata time
set timefmt "%Y-%d"
set format x "%Y\n%d"
plot FILE u (StartDate=timecolumn(1)):1 index 0 every ::0:0:0
EndDate = strptime("%Y-%d","2020-12")
f(x) = a*(x-StartDate) + b
FIT_LIMIT = 1e-8
fit f(x) FILE u (timecolumn(1)):2 via a,b
set terminal png truecolor size 620,420 background rgb "#eff1f0"
set output "/xxx/xxx/xxx/data.png"
set xrange[StartDate:EndDate]
set grid xtics, ytics
set yrange[0:30]
#set xtics rotate by 90
set format y "%g"
myLabel(n) = sprintf("%g",n)
plot FILE u (timecolumn(1)):2 w lp pt 7 lc rgb "red" notitle, \
'' using 1:2:(myLabel($2)) w labels offset 0,-0.5 notitle, \
f(x) ti "linear fit with extrapolation"
This script works well if I use the data of the current year ( all the lines in data which starts by 2020 ) :
But I would like to include the 3 lines from 2019. But if I keep all my data ( 2019+2020 ), I've this result :
And if I want to extend this graph to the next year by modifying the end date 2020-12 by 2021-01, I've this result :
Someone to tell me why I've this result ?
For the sake of not letting this questions appear unanswerered:
Your timeformat should be %Y-%d (Year-Day), instead of %Y-%m (Year-Month).

How to make a plot of positions with palette in Gnuplot?

How can I make a plot with some values of delta_x and delta_y positions; where I need to use palette (or colorbars) for each point showing their respective epochs (My current plot, and an example of the plot that I would like to make are shown below).
My current Gnuplot code is as follows:
set fontpath '/System/Library/Fonts'
set term post color enh eps font "Helvetica" 14
#Gnuplot script file for plotting data
#Set Line style
set style line 12 lw 1 ps 1 pt 8 # empty triangle
set style line 13 lw 1 ps 0.7 pt 81 #empty circle
#Add Legend
set key top right box
# set plot
set xrange[1.2:0]
set xlabel "Relative R.A. (mas)" # set xlabel
set mxtics 4
set xtics 0, 0.1, 1.2
set yrange[0:1]
set ylabel "Relative decl. (mas)"
set mytics 4
set ytics 0, 0.1, 1
plot "MOD1.dat" using 1:2 w points ls 13 lc rgb 'black' title "Data1", "MOD2.dat" using 1:2 w points ls 12 lc rgb 'gray' title "Data2"
Where my data are as follows:
Data1:
#Year RA(mas) DEC(mas)
1993-06-26 0.36315 0.23913
1993-12-16 0.33392 0.28443
1994-01-28 0.34606 0.30810
1994-12-23 0.37139 0.32989
1995-02-12 0.34050 0.29165
1995-08-17 0.55405 0.42913
1995-12-18 0.36928 0.2777
1996-04-07 0.49601 0.31533
1996-12-13 0.43557 0.34637
1997-11-14 0.36811 0.25562
1998-06-02 0.55603 0.36268
1998-12-07 0.52873 0.23110
2000-11-12 0.45839 0.22572
ieData2:
#Year RA(mas) DEC(mas)
1993-06-26 0.63633 0.44645
1993-09-18 0.63548 0.35586
1993-12-16 0.63161 0.41704
1994-01-28 0.27266 0.47256
1994-03-14 0.75819 0.65255
1994-04-21 0.69664 0.68481
1994-06-21 0.78735 0.72865
1994-08-29 0.91143 0.78274
1994-10-30 0.55326 0.43258
1994-12-23 0.67065 0.54423
1995-02-12 0.55778 0.51656
1995-08-17 1.01458 0.50502
Thank you.
try the palette linetype, like this:
plot 'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt palette

How do I plot multiple Y axis for a single X axis in a single Gnuplot window?

I am using the 32-bit version of GNUPlot in a Window 7 "Professional" OS Environment (...sadly!) and I want to do a "stack-plot" of boxes using ONLY ONE x-axis for ALL which is "TIME" in the format of a series of "Dates".
ALL of the GNUPlot Code works but, each of the plots uses its own individual x-axis which consumes a lot of graphing real estate.
I also need to be able to have variable y-axis scales for each of the stacked-plots...
Here is the "labeled" (CSV) data file:
Date,Time,Weight(kg),Height(cm),BMI,BP Max.(mmHg),BP Min.(mmHg),P/min,% Fat 09/09/2015,13:16:00,77.4,171,26.5,121,73,75,22.5 16/07/2015,09:14:34,76.9,170,26.6,111,70,76,23.5 26/06/2015,18:14:48,76.9,170,26.6,123,72,78,23.2 19/06/2015,08:45:42,77,172,26,96,60,89,22.1 15/06/2015,12:29:48,77.7,170,26.9,117,73,87,23.6 15/06/2015,12:15:58,77.8,170,26.9,127,76,77,23.7 15/06/2015,12:11:05,77.7,171,26.6,118,74,83,22.8 23/03/2015,16:39:55,78.6,170,27.2,119,72,78,24 20/03/2015,09:07:30,77.6,169,27.2,138,74,77,24.1 09/01/2015,14:30:00,79.2,170,27.4,114,71,75,24.1 07/10/2014,16:06:00,78.4,171,26.8,119,73,108,24.8 07/10/2014,16:08:00,78.4,170,27.1,109,72,75,25.1 15/09/2014,08:18:23,76.9,171,26.3,116,69,102,24.8 15/09/2014,09:20:27,76.7,172,25.9,132,76,91,21 04/09/2014,12:05:00,75.6,169,26.5,115,71,96,25.4 01/04/2014,11:18:00,76.2,171,26,115,69,70,22.9 19/03/2014,09:48:23,75.3,171,25.8,113,69,55,22.1 14/03/2014,10:39:29,75.6,170,26.2,108,69,78,22.5 05/03/2014,16:45:00,75.9,170,26.3,129,73,84,23.3 09/05/2013,17:31:00,74.5,171,25.5,135,75,92,21
And here is the "current" GNUPlot Code that I am using to generate the 5 stacked plots:
reset
set terminal windows size 1325, 625
set multiplot layout 5, 1 title "Individual Employee Biometric Data vs. Time"
set xlabel "DATE"
set timestamp
set key outside
set key center right
set pointsize 1.0
set grid lw 1
set timefmt "%d/%m/%Y"
set xdata time
set format x "%d/%m/%Y"
set xrange [ "09/05/2013\t0000" : "09/09/2015\t0000" ] noreverse nowriteback
set datafile sep ','
set arrow from 10.0,0 to 10.0, 0.5 lw 3
set label ' ' at 10.2,0.03
set label '(C) 2015' at 2050.0,-0.85
set border lw 2
set yrange [73.0:80.0]
set ylabel "(kg)"
plot 'K8.dat' using 1:3 title "BODY\nWEIGHT" with linespoints lw 2 lt rgb 'red'
set yrange [25.0:30.0]
set ylabel "kg/m^2"
plot 'K8.dat' using 1:5 title "BODY\nMASS\nINDEX" with linespoints lw 2 lt rgb 'green'
set yrange [50.0:150.0]
set ylabel "(mmHg)"
plot 'K8.dat' using 1:6 title "SYS" with linespoints lw 2 lt rgb 'blue', \ 'K8.dat' using 1:7 title "DIAS" with linespoints lw 2 lt rgb 'coral'
set yrange [40.0:120.0]
set ylabel "(bpm)"
plot 'K8.dat' using 1:8 title "HEART\nRATE" with linespoints lw 2 lt rgb 'purple'
set xlabel "DATE"
set yrange [15.0:30.0]
set ylabel "(%)"
plot 'K8.dat' using 1:9 title "BODY\nFAT" with linespoints lw 2 lt rgb 'orange'
PS - This code is from a previous GNUPlot routine so "excuse" the '#" commenting-out...
You can use multiplot to stack several plots on top of each other. You just have to switch off the plot borders appropriately for each, see help set border, and unset the abscissa xtics for all but the lowermost plot.
set multiplot
set origin 0.1, 0.1
set size 0.9,0.3
set xrange [a:b]
plot "first"
set origin 0.1,0.4
unset xtics
set border 2 # only plot left border
plot "second"
set origin 0.1,0.7
plot "third"
unset multi
Crucial is fixing the xrange for all plots, because after switching off the xtics for the following plots, you can't see if it is actually identical.
(too long for a comment)
Ok, I get what you mean by stacked plots now. To my knowledge, having several y-axes (more than 2) above a single x axis is not possible.
What you COULD however do is try to fake more than 2 axes by plotting all data in the roughly 30...150 range on the y(1)-axis, and all data in the 15...30 range on the y2axis. However, the lines would be all kind of overlapping and not as cleanly separated.
Another alternative would be to first normalize all data into an e.g. 0...10 range by subtracting the min value and dividing by max-min, then stacking these on top of each other by adding 0 for the first line, 10 for the second, and so on. However, you would then have to add hand-made y-axis tics (which is possible but somewhat bothersome).
Actually, here is a working template for the fancier solution I outlined above (implemented for three data sets, but can be extended to basically arbitrarily many)
reset
set datafile separator ","
inputfile = 'data0.txt'
stats inputfile using 3 name 'STATS_WEIGHT'
STATS_WEIGHT_range = STATS_WEIGHT_max - STATS_WEIGHT_min
stats inputfile using 4 name 'STATS_HEIGHT'
STATS_HEIGHT_range = STATS_HEIGHT_max - STATS_HEIGHT_min
stats inputfile using 9 name 'STATS_FAT'
STATS_FAT_range = STATS_FAT_max - STATS_FAT_min
# more stats for further data -- apparently needs to be BEFORE the date/time stuff
set timefmt "%d/%m/%Y"
set xdata time
set format x "%d/%m/%Y"
set xrange [ "09/05/2013\t0000" : "09/09/2015\t0000" ] noreverse nowriteback
# define the offset at which the fake y-axes start; decrease or increase offsetIncrease for spacing (effectively: blank labels) between 'graphs'
startYTicsOffset = 0
numberOfFakeYTicsPerData = 6
scalingFactor = 1.0/(numberOfFakeYTicsPerData - 1.0)
offsetIncrease = numberOfFakeYTicsPerData + 0.5
#to get rid of actual yrange numbering, set a dummy label that will be overwritten
set ytics ("dummy" 0)
#increase total actual yrange factor as needed for additional series
set yrange [0: 3 * offsetIncrease]
#add tics for weight, note that %.Xf prints the number with X decimals
do for[i=0:numberOfFakeYTicsPerData-1]{
set ytics add (sprintf("%.0f kg", STATS_WEIGHT_min + i * scalingFactor * STATS_WEIGHT_range) startYTicsOffset+i)
}
#add tics for height
startYTicsOffset = startYTicsOffset + offsetIncrease
do for[i=0:numberOfFakeYTicsPerData-1]{
set ytics add (sprintf("%.1f cm", STATS_HEIGHT_min + i * scalingFactor * STATS_HEIGHT_range) startYTicsOffset+i)
}
#add tics for fat - I couldn't figure out how to get gnuplot to print actual '%' character in sprintf directive (should be '%%' but doesn't appear to work)
startYTicsOffset = startYTicsOffset + offsetIncrease
do for[i=0:numberOfFakeYTicsPerData-1]{
set ytics add (sprintf("%.1f percent", STATS_FAT_min + i * scalingFactor * STATS_FAT_range) startYTicsOffset+i)
}
###### ... add further tics ...
plot inputfile using 1:( 0 * offsetIncrease + ($3 - STATS_WEIGHT_min)/ (STATS_WEIGHT_range * scalingFactor) ) w lp title "weight",\
inputfile using 1:( 1 * offsetIncrease + ($4 - STATS_HEIGHT_min)/ (STATS_HEIGHT_range * scalingFactor) ) w lp title "height",\
inputfile using 1:( 2 * offsetIncrease + ($9 - STATS_FAT_min) / (STATS_FAT_range * scalingFactor) ) w lp title "fat %"
### ... add further data ...
by the way: if you post or edit a question or an answer, try clicking the image icon above the editing window. It will open a little window where you can drag and drop images directly without needing a web hosting service. Like that:

How to specifying yerrorbar style from gnuplot

emphasized textPlotting script that used to work for the previous version of gnuplot
(v4.2.6) no longer work for the latest version (v4.4.0) and produces
error messages for the following script line.
plot "data_file" u ($1+0.5):2 title "legend1" w boxes fs solid 0.85,
"" u ($1+0.5):2:3 notitle w yerrorbars 1,
....
The error goes away as I change "yerrorbars 1" to "yerrorbars".
However, this prohibits the customization of the errorbar style.
Can anyone tell me how can I do this right?
I'm attaching test code that causes the error and the error message.
#!/opt/local/bin/gnuplot
set term postscript monochrome enhanced
set output "test.eps"
set grid x y
set xtics nomirror
set ytics 1.5 font "Helvetica, 18"
set yrange [0:10]
set xrange [0:10]
set boxwidth 1
set bmargin 3
set key top left
plot "test.dat" u ($1+0.5):2 title "test0" \
w boxes fs solid 0.85, \
"" u ($1+0.5):2:3 notitle w yerrorbars 1, \
"" u ($1+1.5):4 title "test1" w boxes fs solid 0.7, \
"" u ($1+1.5):4:5 notitle w yerrorbars 1
I ran above script with the following data.
$ cat test.dat
1 1.315119617 0.131 1.199138756 0.136
7 5.382161114 0.002 4.818144427 0.003
and it generated the following error messages.
$ gnuplot test.plt
plot "test.dat"
....
^ "test.plt", line 17: ';' expected
As I mentioned from above, the error goes away when I change yerrorbar 1 to yerrorbar but this prevent me from specifying error bar style.
Is this what set bars 1 does?
The style of error bars depends on the linestyle which is being used for the plot. So you should specify it like this:
plot "mydata.csv" linestyle 1 with yerrorbars
linestyle 1 is what you need
nblumoe is about the specific style. You can also affect other characteristics, for instance
plot "mydata.csv" linestyle 1 linewidth 2 with yerrorbars

Resources