Gnuplot - setting of xrange - gnuplot

How to set this xrange please to see the function g(x) as the gauss function? Thank you
c = 299792458
kB = 1.380649*10**(-23)
T = 10000
m_he = 6.64424*10**(-27)
nun_he = 4.55746e+14
nuth_he = (2*kB*T/m_he)**(0.5)
konst2 = 11e+12
g(x) = 1-konst2/((pi)**(0.5)*(nuth_he))*exp(-((x-nun_he)**2)/(nuth_he**2))
set xtics rotate by -90
set term pngcairo size 800,1200 enhanced font "Segoe UI,18"
set output "out.png"
set format y "%4.2sx10^{%T}"
x0=4.55746e+14
set xrange [x0-0.00001e+14:x0+0.00001e+14]
plot g(x) with lines lw 2.5 linecolor rgb "medium-blue", "<echo '4.55746e+14 1'" with points ls 7 ps 2

Please check the basics of the Gauss function.
Basically, the factor σ determines the width of the peak (in your case nuth_he).
So if you choose the range for example x0-3σ to x0+3σ you should nicely see your curve.
x0=4.55746e+14
set xrange [x0-nuth_he*3:x0+nuth_he*3]
However, what should this be?
"<echo '4.55746e+14 1'" with points ls 7 ps 2
Drawing a single point or line? But again, this will be orders of magnitudes different in y from your Gaussian curve. With this point or line in the same plot you won't see a peak or dip of your Gauss curve.

Related

Handling out-of-range values with GNUPlot's splot

I use the splot commadn to produce a heat map of the earth. The x- and y-values represent lattitude and longitude of a specific point on the Earth's surface, while the related z-value is the outcome of an analysis. The zrange is between 0 and 60. However, for some locations on Earth, there is no result available (which is correct) and z is set to 9999 for these cases.
I'm using the following script to produce the heat map:
set terminal png large size 1600,\
1200 font arial 24 crop
set output "map.png"
set palette model RGB defined (0 "dark-green",1 "forest-green",2 "green",3 "light-green",4 "dark-yellow",5 "yellow",6 "red",7 "dark-red")
set xrange[-180.00: 180.00]
set yrange[ -90.00: 90.00]
set zrange[ *: 60]
set grid
set pm3d map
set xlabel "Longitude [deg]"
set ylabel "Latitude [deg]"
unset key
set cblabel "Time [h]"
splot "output\\map.dat" u 5:6:8,\
"input\\world.dat" u 1:2:( .00) w l lw 1 lt -1
It works fine but because of the limitation in zrange, regions with z > 60 are shown in white.
I want to have something like a condition which enables that all 9999 z-values are shown in a specific colour like purple with a declaration like "no result" in the legend.
Any idea how to achieve this?
Thanks in advance,
Florian
Not exactly sure how to modify the style for the selected points, but you can use the ternary operator not to draw them at all. Something like:
splot "output\\map.dat" u 5:6:(($8<=60)?($8):(1/0))
You basically want to have 3 "ranges" of colors:
0 to 60 your defined palette colors
>60 "out of range" color
=9999 "no data" color
Not sure if splot ... w pm3d will allow an easy "independent" setting for z and color.
Furthermore, if you have NxN datapoints you will get (N-1)x(N-1) quadrangles and the color is determined by the z-values of the involved vertices (check help corners2color) and http://gnuplot.sourceforge.net/demo_5.5/pm3d.html (the very last graph). Maybe there is an easy way which I am not aware of.
That's why I would perfer the plotting style with boxxyerror (check help boxxyerror), maybe this is not the intended way, but it is rather flexible. If you are running gnuplt 5.4 you have the function palette() (check help palette).
I would take for missing data (backgroundcolor here:white) and for data out of range "grey", but you can easily change it. You can skip the random data generation part and in the plot command replace $Data with your filename and the corresponding columns. As well, replace 180./N and 90./N with the width (delta longitude) and height (delta latitude) of one data element.
Script: (requires gnuplot>=5.4)
### define separate color for missing values
reset session
set xrange[-180:180]
set yrange[-90:90]
# create some "random" test data
N = 90
set samples N
set isosamples N
set table $Data
c = 0.05
x0 = 70 # (rand(0)*360-180) # or random
y0 = -50 # (rand(0)*180-90) #
size0 = 2
x1 = -150 # (rand(0)*360-180) # or random
y1 = -20 # (rand(0)*180-90) #
size1 = 1
holeP0(x,y) = (1-erf((x-x0)*c/size0)**2) * (1-erf((y-y0)*c/size0)**2)
holeP1(x,y) = (1-erf((x-x1)*c/size1)**2) * (1-erf((y-y1)*c/size1)**2)
f(x,y) = rand(0)<holeP0(x,y) || rand(0)<holeP1(x,y) ? 9999 : (sin(1.3*x*c)*cos(.9*y*c)+cos(.8*x*c)*sin(1.9*y*c)+cos(y*.2*x*c**2))*11.5+33
splot f(x,y)
unset table
set palette model RGB defined (0 "dark-green",1 "forest-green",2 "green",3 "light-green",4 "dark-yellow",5 "yellow",6 "red",7 "dark-red")
myZmin = 0
myZmax = 60
myColorNoData = 0xffffff
myColorOutOfRange = 0x999999
set rmargin screen 0.8
set colorbox user origin screen 0.85,graph 0.2 size graph 0.05,graph 0.8
set cblabel "Amplitude"
set cbrange [myZmin:myZmax]
set tics out
set style fill solid 1.0 border
set key noautotitle at graph 1.27, graph 0.15 reverse Left samplen 2
myColor(col) = (z=column(col), z==9999 ? myColorNoData : z>myZmax ? myColorOutOfRange : palette(z))
plot $Data u 1:2:(180./N):(90./N):(myColor(3)) w boxxy lc rgb var, \
"world.dat" u 1:2:(0) w l lc "black", \
NaN w l lc palette, \
keyentry w boxes lc rgb 0x000000 fill empty ti "no data", \
keyentry w boxes lc rgb myColorOutOfRange ti "\ndata out\nof range"
### end of script
Result:

Gnuplot: oscilloscope-like line style?

Is it possible in Gnuplot to emulate the drawing style of an analogue oscilloscope, meaning thinner+dimmisher lines on larger amplitudes, like this:?
The effect you see in the oscilloscope trace is not due to amplitude, it is due to the rate of change as the trace is drawn. If you know that rate of change and can feed it to gnuplot as a third column of values, then you could use it to modulate the line color as it is drawn:
plot 'data' using 1:2:3 with lines linecolor palette z
I don't know what color palette would work best for your purpose, but here is an approximation using a function with an obvious, known, derivative.
set palette gray
set samples 1000
plot '+' using ($1):(sin($1)):(abs(cos($1))) with lines linecolor palette
For thickness variations, you could shift the curve slightly up and down, and fill the area between them.
f(x) = sin(2*x) * sin(30*x)
dy = 0.02
plot '+' u 1:(f(x)+dy):(f(x)-dy) w filledcurves ls 1 notitle
This does not allow variable colour, but the visual effect is similar.
Another approach:
As #Ethan already stated, the intensity is somehow proportional to the speed of movement, i.e. the derivative. If you have sin(x) as waveform, the derivative is cos(x). But what if you have given data? Then you have to calculate the derivative numerically.
Furthermore, depending on the background the line should fade from white (minimal derivative) to fully transparent (maximum derivative), i.e. you should change the transparency with the derivative.
Code:
### oscilloscope "imitation"
reset session
set term wxt size 500,400 butt # option butt, otherwise you will get overlap points
set size ratio 4./5
set samples 1000
set xrange[-5:5]
# create some test data
f(x) = 1.5*sin(15*x)*(cos(1.4*x)+1.5)
set table $Data
plot '+' u 1:(f($1)) w table
unset table
set xtics axis 1 format ""
set mxtics 5
set grid xtics ls -1
set yrange[-4:4]
set ytics axis 1 format ""
set mytics 5
set grid ytics ls -1
ColorScreen = 0x28a7e0
set obj 1 rect from screen 0,0 to screen 1,1 behind
set obj 1 fill solid 1.0 fc rgb ColorScreen
x0=y0=NaN
Derivative(x,y) = (dx=x-x0,x0=x,x-dx/2,dy=y-y0,y0=y,dy/dx) # approx. derivative
# get min/max derivative
set table $Dummy
plot n=0 $Data u (d=abs(Derivative($1,$2)),n=n+1,n<=2? (dmin=dmax=d) : \
(dmin>d ? dmin=d:dmin), (dmax<d?dmax=d:dmax)) w table
unset table
myColor(x,y) = (int((abs(Derivative(column(x),column(y)))-dmin)/(dmax-dmin)*0xff)<<24) +0xffffff
plot $Data u 1:2:(myColor(1,2)) w l lw 1.5 lc rgb var not
### end of code
Result:

Heatmap of points in a volume

I have (x,y,z) points with coordinates like the following figure,
I would like to color the points based on their concentration.
The idea is to make a heatmap of points but in a 3D figure.
I would appreciate very much any help possible.
Regards.
Use data values in a 4th column to index a smooth color palette
splot DATA using 1:2:3:4 with points lc palette
The gnuplot development version now supports calculation of a point density function that can in turn be used to color individual points. This depends on a new set of commands that operate on a 3D grid of voxels. Sample script and output:
set title "Gaussian 3D cloud of 3000 random samples\ncolored by local point density"
rlow = -4.0; rhigh = 4.0
set xrange [rlow:rhigh]; set yrange [rlow:rhigh]; set zrange [rlow:rhigh]
set xtics axis nomirror; set ytics axis nomirror; set ztics axis nomirror;
set xyplane at 0
set xzeroaxis lt -1; set yzeroaxis lt -1; set zzeroaxis lt -1;
set log cb; set cblabel "point density"
# define 100 x 100 x 100 voxel grid
set vgrid $vdensity size 100
vclear $vdensity
# datablock $random has previously been loaded with 3000 points
# in a spherical Gaussian distribution about the origin
# The vfill command adds 1 to each voxel in a spherical region with radius 0.33
# around each point in $random
vfill $random using 1:2:3:(0.33):(1.0)
# plot the same points colored by local point density
splot $random using 1:2:3:(voxel($1,$2,$3)) with points pt 7 ps 0.5 lc palette
Full demo here: voxel demo in gnuplot online collection

Fit histogram in gnuplot

I'm trying to fit data (histogram) in gnuplot. I tried various functions, and by looking at my histogram, I suppose the best fit is lognormal or gamma distribution, but I am not able to do this fit in gnuplot (Im rather new user of gnuplot).
Here is picture of histogram with gaussian distribution:
Also here is code in gnuplot:
reset
n=100 #number of intervals
max=15. #max value
min=0. #min value
width=(max-min)/n #interval width
#function used to map a value to the intervals
hist(x,width)=width*floor(x/width)
set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
#to put an empty boundary around the
#data inside an autoscaled graph.
set offset graph 0.05,0.05,0.05,0.0
set xtics min,(max-min)/5,max
set boxwidth width*0.9
set style fill solid 0.5 #fillstyle
set tics out nomirror
set xlabel "Diameter"
set ylabel "Frequency"
#count and plot
#fac(x) = (int(x)==0) ? 1.0 : int(x) * fac(int(x)-1.0)
gauss(x)=a/(sqrt(2*pi)*sigma)*exp(-(x-mean)**2/(2*sigma**2))
fit gauss(x) 'hist.temp' u 1:2 via a, sigma, mean
plot 'data.list' u (hist($8, width)):(1.0) smooth freq w boxes lc rgb "green" notitle, \
gauss(x) w lines ls 2 lw 2
In file hist.temp is tabular output ( see this link )

Gnuplot x-axis resolution

I'm trying to plot in gnuplot a log-periodic function: cos((log(abs(t-Tc))*PI/log10(lambda) ) + phi)
But because of the nature of log(x) near to x=0, the plot is getting ugly.
How to plot a log-periodic function in gnuplot so it looks nice?
My plot script looks like this:
phi = 1
TcFormated = 9.67e+8
lambda = 2
PI = 3.1415
g(t) = abs(cos((log(abs(t-TcFormated))*PI/log10(lambda) ) + phi))
set tmargin at screen 0.01
set bmargin at screen 0.99
set lmargin at screen 0.01
set rmargin at screen 0.99
set xrange [8.4e+8:1.04e+9]
set yrange [0:1]
unset xtics
unset ytics
plot g(x) t '' w l
pause -1
After setting:
set samples 10000
I got a much better looking graph:
If you want to increase the resolution try
set samples <X>
where <X> is an integer. Per default this integer is set to 100. Increase that number to your needs.
Though, the higher the integer is chosen the longer it will take gnuplot to plot the graph.

Resources