Gnuplot - Plot data on another abscissa by interpolation - gnuplot

Good evening,
I have a problem with Gnuplot. I tried to sum up my problem to make the comprehension easier.
What I have : 2 sets of data, the first one is my experimental data, about 20 points, the second one is my numerical data, about 300 points. But the two sets don't have the same abscissa.
What I want to have : I want my numerical data be interpolate on the x-experimental abscissa.
I know it is possible to do that with Xmgrace (paragraph Interpolation at http://plasma-gate.weizmann.ac.il/Xmgr/doc/trans.html#interp) but with Gnuplot ?
What I want to have in addition : is it possible, then, to subtract the y-experimental data of my y-numerical data at the x-experimental abscissa points ?
Thank you in advance for your answer,
zackalucard

You cannot interpolate the ordinate values of one set to the abscissa values of the other. gnuplot has no mechanism for that.
You can however plot both datasets using one of the smoothing algorithms (check "help smooth") with common abscissa values (which might (be made to) coincide with the original values of one set.)
set table "data1.tmp"
plot dataf1 smooth cspline
set xrange [GPVAL_x_min:GPVAL_X_max] # fix xrange settings
set table "data2.tmp"
plot dataf2 smooth cspline
unset table
Now you have the interpolated data in two temporary files, and only need to combine them into one:
system("paste data1.tmp data2.tmp > correlation.dat") # unixoid "paste" command
plot "correlation.dat" using 2:4
(If you have a sensible fit function for both datasets, the whole thing becomes much easier : plot dataf1 using (fit1($1)):(fit2($1)))

You can use smoothing, this should do the trick
plot "DATA" smooth csplines
(csplines is just one options, there others, e.g. bezier)
But I don't think you can automatically determine the intersection of the smoothed curved. You use the mouse to determine the intersection visually, or alternatively fit some functions f(x) and g(x) to your curves and solve f(x)=g(x) analytically

Related

Gnuplot: Polar plot showing variable ranges

I've got a dataset of angle ranges that I'd like to represent as a polar plot.
The format is as follows:
[Radius]\t[Range 1 lower] [Range 1 upper]\t[Range 2 lower] [Range 2 upper]...
A typical data line looks like this:
1.181 0 0 31.8196 38.3883 141.612 148.18 180 180 211.82 218.388 321.612 328.18
The number of ranges per line can differ, there are also lines without any ranges. Ideally I'd like to end up with a polar plot, where at a given radius the angle between the lower and upper limit of each range is filled, while the rest of the plot is empty.
The ranges do not overlap, but some of them have the same angle as lower and upper limit (for instance the "0 0" range in the example above), what should still be visible, as (as always) those single point and hardly-visible details in the calculation turned out to be those observed in experiment...
For now I've changed the C-program that outputs said ranges to give me a cloud of points with polar coordinates which I plot with dots, but I'd really prefer a kind-of vectorial plot with filled areas, as that'd mean (much) lower file size, and would allow zooming...
Any help would be appreciated, thanks in advance, Andreas
There are purely gnuplot 4.4+ solutions, but they will be intricate. One reason is that polar plotting of data files is not done with polar interpolation, but linear interpolation (straight lines between the endpoints). I would rather have the C program output the gnuplot commands to plot your data directly, e.g.
set polar
set angles degrees
plot (t<38.3883&t>31.8196)?1.181:1/0 with filledcurves above r=0, \
(t<...
I'd advise to treat the 0-range cases separately with set arrow from 0,0 to r*cos(angle),r*sin(angle).
I'm not sure the file will be so much smaller, again gnuplot will generate a polyline to approximate the arc of circle at r=1.181. If you want a small file with actual arcs of circle, you may want to generate svg code directly from your C code.

gnuplot: Plot boxes next to each other of discrete function

How can I plot discrete functions, like the Poisson distribution, in gnuplot with different parameters in the same plot without having them overlap?
For example: I plot the Poisson distribution with lambda = {1,3,5} and with boxes in the same plot. To discretize I do set xrange [1:15]; set sample 15 so that it only plots the discrete values. This works pretty well. The only problem is, that the boxes of the three different Poisson distributions (of the three different lambdas) overlap (because they all have a value at x=1, x=2, etc). Making them transparent looks still ugly (color mixing on overlaps). So I want the function to be displayed shifted. The values of Poisson(x, lambda=1) and Poisson(x, lambda=3) and Poisson(x, lambda=5) should be calculated for x at x, but for each lambda should be displayed slightly more shifted to x than the previous lambda plot so that the all boxes don't overlap and can clearly be seen.
I hope I expressed this clear enough.
With datafiles it's easy (just add something with using $1+0.1:2, e.g.) but how do I shift analytical functions?
In order to plot analytical functions with special needs, which require the using statement, one can use the pseudo filename +. In your case, the plotting script might look as follows:
set xrange[-0.5:15.5]
set samples 16
set style data boxes
set boxwidth 0.2 absolute
set style fill solid noborder
poisson(x) = lambda**x/int(x)!*exp(-lambda)
plot for [lambda=1:5:2] '+' using ($0-(lambda-3)*0.1):(poisson($0)) title sprintf("λ = %d", lambda)

gnuplot: numerical values of points of a function

Is it possible with gnuplot (4.6) to print (in a file or through redirection from standard output) the values of the sampled points of a function.
Say, if I write plot sin(x) with for example set samples 20, I want 20 lines of data giving me the x,y values of the computed points that would be plotted.
I don't care if these are actually plotted or not.
I though that there was some kind of "text" terminal, but it seems that there is none.
This can be done with set table environment
For example:
set table "outputfile.txt"
plot sin(x)
unset table

custom y scale in plot for

I have a data file, looking like
550 1.436e+00 7.857e-01 5.906e-01 4.994e-01 4.574e-01 4.368e-01 4.260e-01 4.273e-01 4.296e-01 4.406e-01 4.507e-01 4.639e-01 4.821e-01 5.008e-01 5.156e-01 5.378e-01 5.589e-01 5.768e-01 5.970e-01 6.196e-01 6.422e-01 6.642e-01
The first column is for x-axis, the rest ones are for the y-axis, 22 curves totally.
I want to plot the data so that y tics represent cube roots of the values. Actually, I want my cubic curves to become linear, to show, that they're cubic in the normal coordinates (and it is fixed by my task to use these coordinates).
I tried to use the following command:
plot for [i=2:23] datafile using 1:(i ** .333) smooth cspline
It expects column number in place of i.
I know, the following is correct:
plot datafile using 1:($2 ** .333) smooth cspline
giving me the desired plot for my first line. But how do I modify this for plot for?
If you want the column number in place of i, you should use column(i) in the using specification.
plot for [i=2:23] datafile using 1:(column(i) ** .333) smooth cspline

gnuplot: display only the roots

Gnuplot, a great package ... I'm in love with it. But we can have our tiffs as well, as any couple :-)
This time, I wanted to simply plot the roots of an equation: say a quadratic to keep things simple. However, I only want two nice round dots appearing on the x-axis representing the point where the quadratic crosses the x-axis or y=0 axis. In other words the roots (when they are real that is).
I don't want to do this with datafile ... I want gnuplot to calculate the roots and plot them.
First off, my attempts: single points aren't really what gnuplot would have you plot, it likes a good wide range of values. Preferably filling up the whole width of your canvas.
It's possible to locate a rectangle at a certain coordinate on your plot, but I wanted a round point. Currently I'm chasing up how to do a tiny filled polygon at that point. I have tried the "samples" option bu it doesn't seem useful.
Also though about defining a dirac-delta function so that only one point would be highlighted (though two would be needed).
ANy suggestions welcome, thanks.
there is a way, but it takes just a little bit of fiddling
narrowness=1
set yrange [0:10]
set xrange [-10:10]
poly(x)=(x**2+3*x-2)
roots(x) =floor(narrowness*poly(x))?1/0:0
plot roots(x) w points pt 7
depending on the function and the range you will need to set the width differently. if you see too many circles increase the narrowness, if you see too few (aka. none) decrease the narrowness
Cheers!
/B2S
oh, and PS. to increase accuracy set samples to some higher value
And Alternatively if you happen to already know the roots, say r1(2,0) and r2(-1,0) then you can plot them using
plot '-' with points pt 7
2 0
-1 0
e
Not sure if this really helps, but if you can define a custom function to calculate the roots, gnuplot will display it.

Resources