Menu

#2535 Sampling ignores logscale when using the special '+' filename

None
closed-not-a-bug
nobody
None
2022-07-26
2022-07-25
Rushi
No

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))?

Discussion

  • Rushi

    Rushi - 2022-07-25
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -6,7 +6,7 @@
     ```
     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 i.e., t=[0.1, 0.104, 0.109, 0.114, ...].
    +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., 
     ```
    
    • Group: -->
    • Priority: -->
     
  • Ethan Merritt

    Ethan Merritt - 2022-07-25

    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

    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))
    

    The character sequence [x=0.1:500] is a range, i.e. it overrides any previous set xrange command. It is not a sampling specification. The sampling is taken from your previous set samples 200 and because the x axis is log scale, the samples are generated accordingly.

    However in your example command

    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)))
    

    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 is t, not x. The program will forgive this, essentially ignoring the x= 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:

    set sample 501
    f(t) = atan2((10*(-1)*((t)**(3)))+(2.6*((t)**(1))),(2*(-1)*((t)**(2))))-atan2((t),((-1)*((t)**(2))+100.25))
    set trange [0:500]
    plot '+' using ($1): (f($1))
    

    Notice that x does not appear in that command. You will get 501 samples on t. 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
  • Rushi

    Rushi - 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. Would

    set logscale x 10;
    set xrange [0.1:500];
    set samples 200;
    plot '+' using (x) : (atan2((10*(-1)*((x)**(3)))+(2.6*((x)**(1))),(2*(-1)*((x)**(2))))-atan2((x),((-1)*((x)**(2))+100.25))) smooth unwrap;
    

    be a good way to achieve what I want? It does seem to give me the plot I want without any errors.

     
    • Ethan Merritt

      Ethan Merritt - 2022-07-26

      Looks OK to me. The danger of using x rather than t 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:

      set angle degree
      set xrange [0:360]
      plot '+' using (cos(x)) : (sin(x)) with lp
      

      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:

      set angle degrees
      set xrange [-1:1]
      plot sample [t=0:360] '+' using (cos(t)) :  (sin(t)) with lp
      

      So even though the plot command you show works as is, I would still write it using t rather than x.

       
      • Rushi

        Rushi - 2022-07-26

        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".

         
  • Ethan Merritt

    Ethan Merritt - 2022-07-26
    • status: open --> closed-not-a-bug
     

Log in to post a comment.