I am trying to plot multiple parametric curves in gnuplot 4.6.
In an earlier version (4.4?), the commands
set para
plot [-pi:pi] for [a=1:10] a*cos(t),a*sin(t)
would result in ten circles centered at the origin with radius 1, 2, ..., 10. In 4.6, the result is one circle of radius 1.
In 4.6, the commands
unset para
plot [-pi:pi] for [a=1:10] a*sin(x)
yield ten beautiful sine curves.
So, it appears that the "for" command now has a problem with parametric curve plotting, I guess.
Does anyone know of a workaround? The circle object is not useful for me: I am interested in general curves. Thanks!
The syntax ambiguity between parametric mode and iteration is a documented bug/limitation in current gnuplot versions. In the development version (4.7) a separate parametric mode is not necessary, as the required sampling variable can be explicitly described in a generic plot command:
plot for [a=1:10] [t=-10:10] '+' using (a*sin(t)):(a*cos(t))
Unfortunately that fully general syntax is not available in version 4.6. The closest I can think of is a simpler variant:
unset parametric
plot for [a=1:10] '+' using (a*sin($1)):(a*cos($1))
This works for your example case, but may not suffice for your actual use case because it conflates the sampling range on the parametric variable with the implicit plotting range on x.
Related
I'm trying to plot this function with gnuplot
but when I try to do it a find this Warning: empty y range [1:1], adjusting to [0.99:1.01]. I think that it should be a precision problem. I can plot it perfectly in another programs, but I would like to know why I can not plot it with gnuplot and how to fix it
Edit:
The command that I'm using is
f(x)=(1-(sinh(1/x))**(-4))**(1/8)
plot [0.01:1.131] f(x)
Two things:
That equation as written does not match the one you showed. Is the exponent supposed to be 4 or -4?
Gnuplot uses integer arithmetic, so (1/8) evaluates to 0. Use either (1./8.) or (.125)
Possible correction (depending on what is the correct exponent):
f(x) = (1. - (sinh(1/x)**(-4)))**(1./8.)
set xrange [0.01 : 1.131]
plot f(x)
is there a way to avoid the drawing of the near asymptote line in the function 1/(2-x), for example, without usage of conditional plotting? The idea is to draw iterated functions based in this one and, since asymptote changes, using conditional plotting isn't a good solution.
You can plot with points at a very high sampling rate:
set yrange [-10:10]
set samples 100000
plot 1/(2-x) with points
If the singularity occurs at different values of x you can use conditional plotting on y:
f(x)=1/(2-x)
set samples 1000
plot (abs(f(x)) < 10 ? f(x) : 1/0) with lines
gnuplot will plot a data file with vectors.
I would like to set something like isosamples=40 and
have gradient vectors plotted for a 2D function.
I know I could write a python program to generate
the data file for the vectors but
I would prefer to do the entire operation within gnuplot.
Any advice?
Would this be a worthy improvement to gnuplot if not yet implemented?
You can use the vectors style and do the computations in gnuplot using the special filename ++.
Suppose that I wish to graph a direction field for the differential equation y'=y*sin(x). I could do this with the following:
set xrange[-2:2]
set yrange[-2:2]
set samples 30
set isosamples 30
unset key
f(x,y) = y*sin(x)
lf(x,y) = sqrt(1+f(x,y)**2)
lyf(x,y) = f(x,y)/lf(x,y)
plot '++' u 1:2:(0.1/lf($1,$2)):(0.1*lyf($1,$2)) with vectors
All of my calculations are done in gnuplot. I compute the direction of the vectors, and scale them to have a length of 0.1, all in the plot command.
I use the special filename '++' which generates a set of points equally spaced over the x and y plot ranges.
See 'help special-filenames' for more details on that.
I have been wondering about this for a while, and it might already be implemented in gnuplot but I haven't been able to find info online.
When you have a data file, it is possible to exchange the axes and assign the "dummy variable", say x, (in gnuplot's help terminology) to the vertical axis:
plot "data" u 1:2 # x goes to horizontal axis, standard
plot "data" u 2:1 # x goes to vertical axis, exchanged axes
However, when you have a function, you need to resort to a parametric function to do this. Imagine you want to plot x = y² (as opposite to y = x²), then (as far as I know) you need to do:
set parametric
plot t**2,t
which works nicely in this case. I think however that a more flexible approach would be desirable, something like
plot x**2 axes y1x1 # this doesn't work!
Is something like the above implemented, or is there an easy way to use y as dummy variable without the need to set parametric?
So here is another ugly, but gnuplot-only variant: Use the special filename '+' to generate a dynamic data set for plotting:
plot '+' using ($1**2):1
The development version contains a new feature, which allows you to use dummy variables instead of column numbers for plotting with '+':
plot sample [y=-10:10] '+' using (y**2):(y)
I guess that's what come closest to your request.
From what I have seen, parametric plots are pretty common in order to achieve your needs.
If you really hate parametric plots and you have no fear for a VERY ugly solutions, I can give you my method...
My trick is to use a data file filled with a sequence of numbers. To fit your example, let's make a file sq with a sequence of reals from -10 to 10 :
seq -10 .5 10 > sq
And then you can do the magic you want using gnuplot :
plot 'sq' u ($1**2):($1)
And if you uses linux you can also put the command directly in the command line :
plot '< seq -10 .5 10' u ($1**2):($1)
I want to add that I'm not proud of this solution and I'd love the "axis y1x1" functionality too.
As far as I know there is no way to simply invert or exchange the axes in gnuplot when plotting a function.
The reason comes from the way functions are plotted in the normal plotting mode. There is a set of points at even intervals along the x axis which are sampled (frequency set by set samples) and the function value computed. This only allows for well-behaved functions; one y-value per x-value.
Which is the theoretical method employed in the csplines smoothing algorithm available in gnuplot? Is it a piecewise least square fit with polynomials? Like a Savitzky–Golay smoothing filter or, as the name suggests, some modification of bsplines? Also: in gnuplot version 4.4 I observed an oscillatory behaviour in the interpolating curve if I employ it for double-logarithmic plots. Is that to be expected?
csplines stands for a cubic spline algorithm. You can see this by typing help csplines in gnuplot, or by looking at the source code (see the functions gen_cubic_spline and intp_cubic_spline in contour.c).
About the oscillations in cubic splines (they are to be expected in some circumstances), see this reference, or this if you can access it.