gnuplot: display only the roots - gnuplot

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.

Related

What the 'set logscale' does in gnuplot?

My question is more about math then the actual code.
When use the command
set logscale
on gnuplot 5.0 what is happening ?
It should represents the logarithmic values values of the x and y points.
But it doesn not seems to work properly. For example on my data I have x and y values smaller then 1 so I am expecting to see negative values for these values on the plot, but I see only postivie values.
What I am doing wrong ?
The logarithmic scale still shows the real values around the axes, just their distances are logarithmic. To really see the negative values, you need to really apply the log function:
plot "file.dat" using (log($1)):(log($2)) with lines
without setting the logscale.
A specific example might help to illustrate the effect of logarithmic scaling:
set xrange [0.1:10]
plot x**2
Let's plot this again, but this time on a logarithmic scale. Watch how the scaling of the x and y axes changes:
set logscale
replot

Is it possible to smoothly change (like a photoshop gradient) the color of a plotted curve as a function of distance from a given point?

Suppose one has a plot like this, for which the peak is at (x,y) = (0,0.40). The distribution is plotted in blue. Is it possible to edit the color scheme of the distribution plot in such a way that the color is a gradient - the farther from x (or y or independently for both) the more the color changes - like this?
I've searched SO for help with this, but only found solutions in which line segments were different colors. But, I want the color transition to be smooth (like this but not 3-D) instead of rough, and I want the color to depend on its distance from a particular value rather than pre-determined "randomly". A different SO post did something similar (not quite what I want though), but could only do so as a scatter plot, which only works for changing colors based on x-value if the peak is at x=0 - I'd prefer it be generalized. As an example, the further from x=0 the redder the curve gets. Ideally, there's a way to do this with a matplotlib colormap.

Gnuplot - Plot data on another abscissa by interpolation

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

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.

Draw axis thru x=0 and y=0

I have a set of data that I'm plotting as a scatter graph which has both positive and negative values on both axis. When I plot this in Flot, the axis are draw at the bottom and the left by default. Is there a way to make it draw the axis through the center of the graph? #X=0 and Y=0?
In other words, instead of this:
I want something like this:
That isn't possible in the default flot. I'm sure it could be hacked in if you wanted to dig into the source, but flot by itself only supports left/right for the y-axis, and top/bottom for the x-axis.
In case anybody else comes across the same need, I created a plugin for Flot and put it here:
https://github.com/burlandm/Flot-Origin-Axis
It does what I need, but I won't make any promises that it'll fit your particular scenario. If I have time, I might try and update it to cover more scenarios.

Resources