As can be seen in the picture attached, the points become too cluttered after a certain point. How do I increase the spacing between points in that region?
Code:
set term jpeg size 1800,900
set output "plot.jpeg"
splot "3d_ME2_31.out" us 1:2:3 lc -1
set grid
set output
I have tried the "every" command but it increasing the spacing in the beginning region too where the point spacing is already high.
Any advice is appreciated. Thanks !
Edit: Data file ( the data to axes mapping is 1:2:3 )
0.94652E+03 0.46588E+02 0.82952E-01
0.94871E+03 0.61601E+02 0.16795E+00
0.95102E+03 0.74087E+02 0.29030E+00
0.95587E+03 0.94012E+02 0.65911E+00
0.95850E+03 0.10204E+03 0.91894E+00
0.96148E+03 0.10885E+03 0.12599E+01
0.96515E+03 0.11542E+03 0.17353E+01
0.96943E+03 0.12040E+03 0.23543E+01
0.97481E+03 0.12578E+03 0.32153E+01
0.98134E+03 0.13077E+03 0.43582E+01
0.98901E+03 0.13507E+03 0.58196E+01
0.99795E+03 0.13948E+03 0.76562E+01
0.10082E+04 0.14377E+03 0.99270E+01
0.10199E+04 0.14800E+03 0.12677E+02
0.10282E+04 0.14775E+03 0.14762E+02
0.10335E+04 0.14413E+03 0.16176E+02
0.10403E+04 0.14050E+03 0.18096E+02
0.10488E+04 0.13621E+03 0.20616E+02
0.10588E+04 0.13205E+03 0.23729E+02
0.10710E+04 0.12798E+03 0.27711E+02
0.10843E+04 0.12370E+03 0.32248E+02
0.10995E+04 0.11973E+03 0.37684E+02
0.11163E+04 0.11572E+03 0.43955E+02
0.11324E+04 0.11203E+03 0.50189E+02
0.11474E+04 0.10875E+03 0.56245E+02
0.11626E+04 0.10553E+03 0.62585E+02
0.11781E+04 0.10217E+03 0.69305E+02
0.11938E+04 0.99038E+02 0.76322E+02
0.12094E+04 0.96412E+02 0.83573E+02
0.12252E+04 0.94002E+02 0.91126E+02
0.12411E+04 0.91794E+02 0.98981E+02
0.12571E+04 0.89765E+02 0.10714E+03
0.12732E+04 0.87918E+02 0.11559E+03
0.12894E+04 0.86536E+02 0.12432E+03
0.13054E+04 0.84701E+02 0.13318E+03
0.13213E+04 0.82945E+02 0.14227E+03
0.13373E+04 0.81284E+02 0.15161E+03
0.13533E+04 0.79678E+02 0.16122E+03
0.13694E+04 0.78071E+02 0.17111E+03
0.13855E+04 0.76542E+02 0.18127E+03
0.14008E+04 0.74960E+02 0.19118E+03
0.14159E+04 0.73330E+02 0.20115E+03
0.14309E+04 0.71898E+02 0.21132E+03
0.14458E+04 0.70357E+02 0.22162E+03
0.14607E+04 0.68300E+02 0.23218E+03
0.14758E+04 0.66454E+02 0.24304E+03
0.14907E+04 0.64530E+02 0.25400E+03
0.15055E+04 0.62676E+02 0.26517E+03
0.15204E+04 0.60999E+02 0.27663E+03
0.15354E+04 0.59429E+02 0.28833E+03
0.15500E+04 0.57764E+02 0.30002E+03
0.15641E+04 0.56109E+02 0.31144E+03
0.15758E+04 0.53850E+02 0.32117E+03
0.15882E+04 0.51118E+02 0.33162E+03
0.16010E+04 0.48445E+02 0.34255E+03
0.16127E+04 0.45813E+02 0.35263E+03
0.16249E+04 0.43266E+02 0.36339E+03
0.16373E+04 0.40811E+02 0.37449E+03
0.16498E+04 0.38485E+02 0.38581E+03
0.16620E+04 0.36479E+02 0.39707E+03
0.16742E+04 0.34549E+02 0.40846E+03
0.16860E+04 0.32632E+02 0.41963E+03
It would be complicated to limit the point reduction to a certain region, but you can do it globally using the pointinterval property of the style with linespoints. If you want to hide the line you can set the linetype to "nodraw": with linespoints lt nodraw pi 5. But that would get you back to the same result as using every to filter the points. The nice thing about using pointinterval instead is that the line goes through all the points even though not all of them are shown. So a jog in the line can highlight an outlier that might otherwise be hidden.
#Plot every 5th point
splot 'DATA' with linespoints pointinterval 5
I would say whether your data points look cluttered or cramped does not only depend on your data but also on your viewpoint.
If you have so many data points why don't you simply plot it with lines? Or as Ethan suggested with linespoints and a certain pointinterval or pointnumber (check help lp).
Script:
set multiplot layout 2,1
set view 60,30
splot $Data u 1:2:3 w p pt 1
set view 71,333
splot $Data u 1:2:3 w p pt 1
unset multiplot
Result: (same datapoints just different viewing angles)
Consider the following file that I want to plot using gnuplot: Servos20211222_105253.csv
# Date/Time 2021/12/22, 10:52:53
# PonE=0,LsKp=200,LsKi=0,LsKd=250,HsKp=40,HsKi=0,HsKd=130,Sp=800,TDEC=1175137
#
# Rel. Time, currentPos, PosPID, currentSpeed, speedPID, Lag, ServoPos
0.00000,4693184,0,0,0,0,4693184
0.00000,4693184,2300,0,368,0,4693184
0.00391,4693185,2300,12,367,0,4693184
:
:
I would like to:
set the plot title to the date/time from the first comment record.
display the record that starts "# PonE" as a caption.
extract the value for TDEC and plot a horizontal line with the name "Target"
I have some influence over the format of the header records, so if (for example) it would be better that they were not comments but provided in some other way, then that can be done.
It is a common problem to get text values from files using only gnuplot. If you can use OS and shell dependent solutions, I'd suggest to use remove the comments from the file and try something like
set title "`head -1 Servos20211222_105253.csv`"
You can place text anywhere using set label <"label text">, where the label text can be the 2nd line from the file.
You can plot a straight line using plot:
p sin(x), 0.5 title "TDEC"
But instead of 0.5, you need to get the value using shell scripts again, e.g. the cut unix command.
There are ways with gnuplot only, although sometimes a bit cumbersome compared with using tools which you have available on Linux (or comparable tools which you need to install on Windows).
Update: shorter and "simplified" script
One possible gnuplot-only way:
set commentschar to nothing, i.e. ''
assign the columns to variables and/or arrays, e.g. myDate, myTime, P[1..9].
Merge P[1..8] into a multi-line string Params by "mis"-using sum (check help sum)
Convert P[9] into a floating point number TDEC for plotting
Script: (modified the data a bit just for illustration)
### extract values from headers with gnuplot only
reset session
$Data <<EOD
# Date/Time 2021/12/22, 10:52:53
# PonE=0,LsKp=200,LsKi=0,LsKd=250,HsKp=40,HsKi=0,HsKd=130,Sp=800,TDEC=1175137
#
# Rel. Time, currentPos, PosPID, currentSpeed, speedPID, Lag, ServoPos
0.00000,1300000,0,0,0,0,4693184
0.00200,1200000,2300,0,368,0,4693184
0.00391,1100000,2300,12,367,0,4693184
EOD
set datafile separator comma commentschar ''
array P[9] # array to store parameters
stats $Data u ($0==0 ? (myDate=strcol(1)[3:], myTime=strcol(2)) : \
sum [_i=1:9] (P[_i] = _i==1 ? strcol(_i)[3:] : strcol(_i) ,0 )) \
every ::0::1 nooutput
set datafile commentschar # set back to default
Params = P[1]
Params = (sum [_i=2:8] (Params=Params.sprintf("\n%s",P[_i]),0),Params)
set title sprintf("%s %s", myDate, myTime)
TDEC = real(P[9][6:]) # convert to real number
set label 1 at graph 0.02, first TDEC P[9] offset 0,-0.7
set label 2 at graph 0.02, graph 0.85 Params
plot $Data u 1:2 w lp pt 7 title "Data", \
TDEC w l lc "red" title "Target"
### end of script
Result:
Tracking the battery discharge / charge on my phone. Data shaped like a 'V'. Charge percentage and elapsed time in seconds, like this:
100,0
74,8103
51,15304
24,23407
2,30609
23,33286
55,37360
76,40064
100,44132
Here's how I'm processing n files and plotting them together:
plots=""
my_xrange=0
files=system("ls -1B data/*.csv | sort -k2 -t '-'")
do for [ file in files ] {
this="'".file."' ".'using ($2/3600):1 notitle, '
plots=plots.this
}
eval('plot '.plots)
(happy plot elided because of too many links)
Then the boss comes by and says the "uphills" are distracting, can I plot just the "downhills" pretty please? No worries, stats will give me the minima, so I xrange. Woot!
plots=""
my_xrange=0
files=system("ls -1B *.csv | sort -k2 -t '-'")
do for [ file in files ] {
stats file using ($2/3600):1 prefix "STATS" nooutput
if ( STATS_pos_min_y > my_xrange ) { my_xrange = STATS_pos_min_y }
this="'".file."' ".'using ($2/3600):1 notitle, '
plots=plots.this
}
print sprintf( 'stats: plot xrange is %.2f', my_xrange )
set xrange [0:my_xrange]
eval('plot '.plots)
xrange obliterates some uphills
I know there's got to be a way to just not plot the uphills, so I wind up with using conditional.
this="'".file."' ".'using (($2/3600) <= STATS_pos_min_y ? $1 : 1/0) notitle, '
which does effectively kill the uphills, but does two bad things to the plot:
the X axis values don't match the previous plot
the plot lines are merged on top of one-another
broken things
I need to use $2/3600 because I want things to be expressed in terms of hours. Oh, sure, I could write a script to massage the data before it even gets to gnuplot, but that's admitting defeat.
What have I not understood in my use of using?
The plot command for your whole data (purple line) is
plot file using ($2/3600):1 with linespoints
while that for the conditional data (blue line) is
plot file using ((($2/3600) <= STATS_pos_min_y) ? $1 : 1/0) with linespoints
This using statement selects only those data points for which ($2/3600) <= STATS_pos_min_y. However, you do not specify where on the x-axis those data points should be plotted, so gnuplot assumes it's just the line number in the data file (0,1,2,3,4). You have to specify the position on the x axis just like you did in the unconditional plot:
plot file using ($2/3600):((($2/3600) <= STATS_pos_min_y) ? $1 : 1/0) with linespoints
should do it.
By the way, formatting is rather limited in SO comments. To post code it's usually better to edit the question where you have more formatting options.
I have three columns data.txt file. I would like to fill the area with color between upper and lower bound. How can I do that? My data.txt file goes as follows,
#Time Force SD
0.000 42.155 1.974
4.890 48.548 3.773
16.102 53.244 4.959
24.215 58.864 5.677
37.698 72.483 4.828
69.354 78.334 3.557
85.586 83.071 7.040
101.155 84.780 5.411
plot "data.txt" u 1:($2+$3) and u 1:($2-$3) w filledcurve (Is there any thing like this?)
Many thanks!
Just use three columns in the using statement (see also help filledcurves):
plot 'data.txt' using 1:($2-$3):($2+$3) with filledcurves
I'm having a problem with pm3d. I have data in the format x y # # # #, and I want to add the four #'s and plot their sum versus x,y with something like this:
set pm3d map
splot 'data' 1:2:($3 + $4 + $5+ $6)
I've made sure that my data has lines wherever the first number changes, but I'm getting the error:
';' expected
after data. If I get rid of everything after data then gnuplot is able to plot, but of course the plot is not what I want.
You're missing the keyword using.
splot 'data' using 1:2:($3+$4+$5+$6)
I suppose it's an easy one to miss because in the examples it is often abbreviated u:
splot 'data' u 1:2:...