Spacing between points in graph in gnuplot - gnuplot

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)

Related

Plot error_bars with lines in gnuplot

I have a file with the delivery rate of a simulation and its confidence interval. I need to plot an error bar on my chart. Need to be the line graph and also the error bar on a single chart
Sample data:
V D IC
10 99.2373 0.000200729
30 97.2515 0.00649952
60 94.6761 0.00950475
I would like it to look like the example below:
Here is my code:
set nokey
set grid
set key right inside
set xlabel 'Velocidade em Km/h'
set ylabel 'Taxa de Entrega'
set autoscale
set yr[0:100]
set style data lines
plot 'taxa_entrega-AODV-50-250.txt' using 1:2:($2-$3):($2+$3) with yerrorbars
if you are plotting errorbars you typically plot data with points but not necessarily with connected lines or linespoints. Instead you add a line described by a model or fit.
However, from the image you are referring to I assume you want to have the points nevertheless connected. So, simply add ,\ the same data '' again as lines.
plot 'taxa_entrega-AODV-50-250.txt' using 1:2:($2-$3):($2+$3) with yerrorbars,\
'' using 1:2 with lines
Addition: See below what you get with the full code. (I commented out the set yrange[0:100] because otherwise one wouldn't see too much with the data you provided. Furthermore, your errobars are in the range of 0.0002 to 0.009. Relative to the values 94.6 to 99.2, these will not be bars but more points.
reset session
set nokey
set grid
set key right inside
set xlabel 'Velocidade em Km/h'
set ylabel 'Taxa de Entrega'
set autoscale
# set yrange[0:100]
set style data lines
plot 'taxa_entrega-AODV-50-250.txt' using 1:2:($2-$3):($2+$3) with yerrorbars,\
'' using 1:2 with lines

gnuplot automatically orders data?

I have two data series:
2.72121 -1326.8380227810
2.81569 -1326.8407684060
2.91018 -1326.8428301680
3.00466 -1326.8448265650
3.09915 -1326.8470902260
3.19364 -1326.8497826100
3.28812 -1326.8530603940
3.38261 -1326.8571516770
3.47710 -1326.8628214990
3.57158 -1326.8694360090
3.66607 -1326.8759488230
3.76056 -1326.8820177910
3.85504 -1326.8875129030
3.94953 -1326.8923946780
4.04401 -1326.8966652370
4.13850 -1326.9003601490
4.23299 -1326.9035228070
and
4.23299 -1326.9035228070
4.13850 -1326.9003601490
4.04401 -1326.8966652370
3.94953 -1326.8923946780
3.85504 -1326.8875129030
3.76056 -1326.8820177910
3.66607 -1326.8759488230
3.57158 -1326.8694360090
3.47710 -1326.8628214990
3.38261 -1326.8571516770
3.28812 -1326.8530603940
3.19364 -1326.8497826100
3.09915 -1326.8470902260
3.00466 -1326.8448265650
2.91018 -1326.8428301680
2.81569 -1326.8407684060
2.72121 -1326.8380227810
which are the same data series but in reverse order. That's for the first series:
and that's for the second one:
The full gnuplot code is:
set loadpath 'C:\Users\sjojungfrun\Programs\gnuplot\palettes'
load 'parula.pal'
set lmargin 10
unset key
set xtics font 'arial,16'
set ytics font 'arial,16'
set grid ytics
e_kcal = 627.509391
b_angs = 0.52918
stats "reverse_scan_coord.dat" nooutput
e_min = STATS_min_y
plot "reverse_scan_coord.dat" u ($1 * b_angs):(($2 - e_min) * e_kcal) w lp pt 7 lw 2 lc 11 #smooth csplines
I am using the Windows Version 5.0 patchlevel 5 of gnuplot.
Am I doing something wrong? I am really surprised about this auto-ordering feature.
If you don't reverse the xrange, the x-values are ranged from smaller/less positive to larger/more positive.
By default, gnuplot connects points in the plot that were neighboring data points in the data file.
In your case one can thus indeed say that the graph is drawn from right to left, as mentioned in the comments.
Although the question is answered and OP's misunderstanding is clarified, let me add some code for creating a plot which would satisfy OP's initial understanding, i.e. gnuplot would automatically adjust the axis direction depending on the direction of the data.
So, strictly speaking, this is not an answer, but an addition which might be useful to somebody for some (very special) cases.
Well, typically, either you know beforehand what direction your data has or you always want to plot it with either increasing (noreverse) or decreasing (reverse) x-values.
What the code does: checking the first and last datapoint and if the last one is smaller than the first one it sets the axis direction to reverse otherwise to noreverse. If I overlooked a simple gnuplot option for this, please let me know.
Code:
### automatically set axis in same direction as data
reset session
$Data1 <<EOD
2.72121 -1326.8380227810
2.81569 -1326.8407684060
2.91018 -1326.8428301680
3.00466 -1326.8448265650
3.09915 -1326.8470902260
3.19364 -1326.8497826100
3.28812 -1326.8530603940
3.38261 -1326.8571516770
3.47710 -1326.8628214990
3.57158 -1326.8694360090
3.66607 -1326.8759488230
3.76056 -1326.8820177910
3.85504 -1326.8875129030
3.94953 -1326.8923946780
4.04401 -1326.8966652370
4.13850 -1326.9003601490
4.23299 -1326.9035228070
EOD
$Data2 <<EOD
4.23299 -1326.9035228070
4.13850 -1326.9003601490
4.04401 -1326.8966652370
3.94953 -1326.8923946780
3.85504 -1326.8875129030
3.76056 -1326.8820177910
3.66607 -1326.8759488230
3.57158 -1326.8694360090
3.47710 -1326.8628214990
3.38261 -1326.8571516770
3.28812 -1326.8530603940
3.19364 -1326.8497826100
3.09915 -1326.8470902260
3.00466 -1326.8448265650
2.91018 -1326.8428301680
2.81569 -1326.8407684060
2.72121 -1326.8380227810
EOD
DirectionCheck(data,colX) = \
sprintf('stats %s u (column(0)==0 ? x0=column(%d):x1=column(%d)) nooutput; \
if (x0>x1) { set xrange[:] reverse } \
else { set xrange[:] noreverse }',data,colX,colX)
set multiplot layout 2,1
set ytic 0.02
SetDirection = DirectionCheck('$Data1',1)
#SetDirection
plot $Data1 u 1:2 w lp pt 7 lc "red"
SetDirection = DirectionCheck('$Data2',1)
#SetDirection
plot $Data2 u 1:2 w lp pt 7 lc "blue"
unset multiplot
### end of code
Result:

Draw a line in a pm3d map

I have a and I want to overplot on it a .
I define the line as a 3d line with constant height and I thought that with this method I have the possibility to overplot them one to another but, unfortunately, I failed.
I realized in fact that the density map routine in gnuplot take the points of the line too.
This is my script:
reset
#set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
#set output "map.png"
set title 'Map'
m_star=1.054
m_1=0.0093866
m_3=0.0078635
fact1 = (m_star+m_1)**0.5
fact2 = (m_star+m_3)**0.5
set pm3d map interpolate 1,1
set xrange [50.22:52.27]
set yrange [30.29:31.17]
splot "file.txt" u (fact1)*(($1)**(-1.5)):(fact2)*(($2)**(-1.5)):6 notitle ,\
"line.txt" notitle
And here the two files: line and density map.
It is possible to overplot them, in gnuplot?
Thanks a lot for your help !
If you set pm3d, this style is used for all plots unless you explicitely specify a different plotting style. So you must use
splot "file.txt" u (fact1)*(($1)**(-1.5)):(fact2)*(($2)**(-1.5)):6 ,\
"line.txt" with lines
in order to plot line.txt as line:

Splot with pattern-filled closed curves and colorbar in Gnuplot

I've got two datafiles that I need to plot, First datafile "surface.dat" is an Nx3 matrix which contains the x y z data.
Am splotting with pm3d and set viewmap to get the 2D projection map of my current surface where the z data defines the range of the colorbar.
The second data file "closed_curve.dat" lies on the x-y plane with no z components. Its very easy to plot the surface and curve in the same graph by using
set view map
set cbrange...
set xrange...
set yrange...
splot "surface.dat" u 2:1:3 title "" w pm3d ,"closed_curve.dat" u 1:2:(0) title ""
Since its a closed curve however, I want to fill it with one of the gnuplot patterns but I can't find anything that works.
A closed curve in the form of a rectangle for example can just be created as an object without the need of a data file and filled in so that's not a problem e.g
set object 1 rectangle from 0,0 to 0.4,0.8 front fc lt 1 fs pattern 2 lw 2
Thanks in advance....
I think your best option is using an external tool to create a polygon object based on your data file:
set macros
polystr = system('awk -v "ORS= " "{printf \"%s %f,%f \",s,\$1,\$2; s = \"to\"}" closed_curve.dat')
set object 1 polygon fillstyle pattern 5 from #polystr
splot "surface.dat" using 2:1:3 with pm3d
I'm not sure if there is any limit on the allowed line length which you may hit with polystr. Maybe you'll need to write the command to a temporary file and the load this.

gnuplot : 3d plot an electromagnetic wave function

Is it possible to do this with gnuplot? Something like on this image (link)
http://i.stack.imgur.com/mZ3M0.gif
I cannot seem to be able to set x = sin(y) and z = sin(y) independently. seeking help!
Thank you!
Yes! You're in luck, I figured this out last week. Here is the gnuplot code I use:
#!/usr/bin/env gnuplot
reset
set term png lw 2
set out 'test.png'
set style data lines
# Set x,y,z ranges
set xr [0:10]
set yr [-2:2]
set zr [-2:2]
# Rotates so that plots have a nice orientation.
# To get parameters, plot in interactive terminal and use 'show view' command.
set view 45,30,1,1
set arrow from 0,0,0 to 10,0,0
unset border
unset tics
splot '+' u 1:(0):(sin($1)) t 'E', \
'+' u 1:(-sin($1)):(0) t 'B'
And here is the figure I get:
I don't have labels, but you can use set label and more arrows to reproduce your example.
You can also define curves like this parametrically:
set parametric
splot u,0,sin(u) title 'E',\
u,-sin(u),0 title 'B'
Note that the u here isn't shorthand for using as you'll often see. u is a dummy variable used in parametric "s"plotting by gnuplot.

Resources