The sample
keyword in the syntax plot sample [x=min:max] ’+’ using (x):(f(x))
seems to ignore logscale settings. For example, the (incorrect?) syntax
set logscale x 10; set samples 200; plot [x=0.1:500] '+' using (x) : (atan2((10*(-1)*((x)**(3)))+(2.6*((x)**(1))),(2*(-1)*((x)**(2))))-atan2((x),((-1)*((x)**(2))+100.25)))
without the sample
keyword, produces the plot I want, with exponentially spaced samples identical to the corresponding function plot,
set logscale x 10; set samples 200; plot [x=0.1:500] atan2((10*(-1)*((x)**(3)))+(2.6*((x)**(1))),(2*(-1)*((x)**(2))))-atan2((x),((-1)*((x)**(2))+100.25))
These samples are at t=[0.1, 0.104, 0.109, 0.114, ...].
But, when I use the correct syntax from the documentation, i.e.,
set logscale x 10; set samples 200; plot sample [x=0.1:500] '+' using (x) : (atan2((10*(-1)*((x)**(3)))+(2.6*((x)**(1))),(2*(-1)*((x)**(2))))-atan2((x),((-1)*((x)**(2))+100.25)))
I get equally spaced samples that ignore the logscale setting, i.e., t=[0.1, 2.61,5.12,...].
Is there a way to preserve logarithmic sampling in plot sample [x=min:max] '+' using (x) :(f(x))
?
Diff:
I seriously suggest never to put ranges in a plot statement. It only leads to confusion. Yeah, it was introduced way back when, recommended in the documentation, and used in the demos. But as the number of program options grew and particularly when you start mixing in explicit sampling, the marginal benefit of allowing a range inside the plot statement, as opposed to a separate
set xrange
statement, is just not worth the added ambiguity and confusion.In your example command
The character sequence
[x=0.1:500]
is a range, i.e. it overrides any previousset xrange
command. It is not a sampling specification. The sampling is taken from your previousset samples 200
and because the x axis is log scale, the samples are generated accordingly.However in your example command
sample [x=0.1:500] '+' ...
is not a range on x. It is sampling specification for the subsequent pseudofile '+'. It does not affect the range on x, and furthermore there are two problems with it. (1) The sampling axis ist
, notx
. The program will forgive this, essentially ignoring thex=
part of it. (2) Sampling limits are always integers, so the lower bound becomes int(0.1)=0. Thus the program sees this as the equivalent of:Notice that
x
does not appear in that command. You will get 501 samples ont
. For each one the plot command will generate a point with x=t and y=f(t). The first point will generate an error because x=t=0 and that is not allowed for a log scale axis.Edit (I was wrong to suggest this part). I had not rememberted that the program is smart enough to adjust the sampling on t when x is logscale. I am deleting that part of my original comment.
[ deleted text about log scale sampling on t axis]
I hope that helps.
You might also want to look at the demo file "sampling2.dem".
If there is some statement in the current documentation or help text that seems to contradict this or lead the reader astray, that's probably an error that should be fixed. So if you can point to particular places, I will try to clarify or fix them.
Last edit: Ethan Merritt 2022-07-25
Thank you for the detailed explanation. I admit, the fact that sampling is happening in t, and not x, when using
(x):(f(x))
should have been clear, but wasn't. Wouldbe a good way to achieve what I want? It does seem to give me the plot I want without any errors.
Looks OK to me. The danger of using
x
rather thant
comes when the generated coordinates don't match the xrange. This isn't a problem with the plot you show here, but consider for example:This generates a circle, but it's crammed all the way over at the left edge because in order to sample the entire circle with x as the dummy variable, the xrange needs to go all the way to 360. This problem goes away if you use t:
So even though the plot command you show works as is, I would still write it using t rather than x.
That makes sense. In the package I am writing, all the plots are really function plots, not parametric plots, They are all of the form
(x):(f(x))
, so xrange will always match the generated coordinates.I just need the
'+' using (x):(f(x))
syntax to enable the smooth unwrap functionality for function plots.Thanks for your help. I think this can be closed, then, as "not a bug".