Menu

#2074 parametric, trange, logscale causes problems

None
closed-fixed
nobody
2018-10-07
2018-09-24
Klaus
No

In gnuplot 5.2.4, I see a problem with the trange in parametric plot and logscale. I used the Windows package gp524-win64-mingw_3.exe .
(I observed that by reactivating a script I successfully run with a 5.0.? version whereit worked fine. Unfortunately, I cannot figure out the patchlevel, but is was before Feb 2017.)

The attempt is to make a parametric plot in logscale. Therefore, a function is used to scale the t-variable in a way that the points are well spread within the range. Thus, I use a trange of [0:1] and scale it in a convenient way. The plotted points are, however, in completly different ranges - it could be [1:100] or so. Here is a small working example:

# x-axis
xmin=600.
xmax=1e5
set xrange [xmin:xmax]
set logscale x

# parametric
set parametric
set trange [0:1]

# scale [0,1] logarithmically to [xmin,xmax]
kot(t) = xmin*exp(t*log(xmax/xmin*1.))

# plot
p \
600+1e3*t, 10.*t w l ls 1, \
kot(t),1+t w l ls 2

The range that are used in the plot are

  • 1600-10600 for the first line
  • out of range for the second line

I checked the following:

  • trange is confirmed to have the correct values [0:1] by show trange
  • by redirecting the output to a table, I confirmed that the used values of t are not consistent
1 Attachments

Discussion

  • Klaus

    Klaus - 2018-09-24
    • Group: -->
    • Priority: -->
     
  • Karl Ratzsch

    Karl Ratzsch - 2018-09-24

    Bit simpler example, it looks like if logsc is set, the parametric plot does not use t but 10^t

    reset;set samp 10
    
    set logscale x
    set parametric
    set trange [1:2]
    
    plot t,t w lp
    
    set table;rep;unset table
    

    Same behaviour already in 5.2pl0, but not 5.0pl7.

     

    Last edit: Karl Ratzsch 2018-09-24
  • Ethan Merritt

    Ethan Merritt - 2018-09-24

    I may not understand what you are trying for, but I thnk you are applying manually a scaling step that the program already does for you automatically, which results in the scaling being applied twice.

    When x is logscaled, the program generates samples that are exponentially spaced so that they come out at equal visual intervals across the plot. I.e. if xrange [1 : 1.e04] then 5 samples would be generated at 1 10 100 1000 10000. Your kot(t) function is applying another exponential on top of that.

    Parametric mode is kind of a vestigial relic at this point. Does the plot come out as explected if you instead use '+'?

      plot  '+' using (kot(x)) : (1+x)
    
     
  • Klaus

    Klaus - 2018-09-25

    Dear Ethan,
    thank you for the proposed workaround, it worked well. However, the behavior of parametric mode and trange is somewhat unexpected, and seems not be be consistent within the versions 5.0 and 5.2.

    As you pointed out that for this specific task, parametric mode is not the only way to do that: I reduced my plotting script to what I thought was a minimal example (although Karl Ratzsch improved that, thanks!), so it was not clear what I was trying to do. In order to clarify the background of my post, I wrote a simplified version of the task - unless I am not sure if this is the appropriate place for it.

    In the whole plot, I show functions

    • f: x1 --> y1
    • and g: y2 --> x1
      Thus my idea was to plot this in parametric mode. However, since x1 and y2 have different ranges, I need to scale the trange in parametric mode by some functions x1scale(t) and y2scale(t)
    plot \
    x1scale(t), f(x1scale(t)) axes x1y1 w l ls 1, \
    g(y2scale(t)),y2scale(t) axes x1y2 w l ls 2
    

    Here is a working example, the parametric option is commented out, and the '+'-workaround is enabled.

    reset;set samp 10
    
    # parametric mode
    set parametric
    set trange [0:1]
    
    #x-axis
    set logscale x
    set xrange [1e1:1e4]
    
    #y-axis
    set logscale y
    set yrange [1e1:1e10]
    
    #y2-axis
    set y2range [0:1]
    
    # functions
    f(x1)=exp(x1)
    g(y2)=1e3*(1+sin(y2))
    
    # scaling of t
    x1scale(t) = 1e1*exp(t*log(1e3))
    y2scale(t) = t
    
    # plotting with parametric mode
    # -- not working this way ...
    # plot \
    # x1scale(t), f(x1scale(t)) axes x1y1 w lp ls 1, \
    # g(y2scale(t)), y2scale(t) axes x1y2 w lp ls 2
    
    
    # plotting with workaround
    unset parametric
    # requires scaling x1 --> y2 
    y2ofx1(x1) = ( log10(x1/1e1)/log10(1e4/1e1) ) 
    plot \
    '+' u (x):(f(x)) axes x1y1 w lp ls 1, \
    '+' u (g(y2ofx1(x))):(y2ofx1(x)) axes x1y2 w lp ls 2
    

    Of course, I'm looking forward also to other solutions to plot simultaneously functions y1(x1) and x1(y2).
    Best regards,
    Klaus

     
    • Karl Ratzsch

      Karl Ratzsch - 2018-09-26

      There's another way to give different sampling ranges for subplots. See alsohelp special filename.

      plot \
         sample [t=0:pi] '+' us (cos(t)):(sin(t)), \
         [t=.5*pi:1.5*pi] '+' us (cos(t)*1.05):(sin(t)*1.05, \
         [t=pi:2*pi] '+' us (cos(t)*1.1):(sin(t)*1.1)
      

      (the keyword "sample" has to be given in front of the first subplot only)

      If logsc x is set, '+' generates logspaced datapoints. '++' doesn't do that, but I'm not sure how exactly that is intended to work, the help doesn't mention logscaled sampling (or I didn't read properly).
      And if logscale is set, '+' produces a warning clone_linked_axes called for axes that are not linkd

       
      • Ethan Merritt

        Ethan Merritt - 2018-09-26

        The details of how the t axis can be explicitly sampled have changed several times, so I would have to go back to the source code for a particular version to see what it does there. In general I suspect that the combination of logscale + sampling + parametric is not as well tested as other plotting modes.

        The warning clone_linked_axes called for axes that are not linkdis harmless. It was a debugging message that was left in the release version by mistake.

         
  • Ethan Merritt

    Ethan Merritt - 2018-09-26

    OK I agree it's a bug, or at least it does not work the way I would expect.
    I'll look into it as a possible fix for 5.2.5.

     
  • Ethan Merritt

    Ethan Merritt - 2018-09-27

    I think I have this working in 5.3 and will back-port the fix for 5.2.5

    I notice that the code involved contains comments from a long time ago that ask "Would anyone ever want to set the t axis to log scale?" Is your application a case where the answer is "yes"? The command "set log t" has never been allowed but perhaps it could be in the future.

     
  • Klaus

    Klaus - 2018-09-27

    "Would anyone ever want to set the t axis to log scale?"
    Is your application a case where the answer is "yes"?

    I would agree: The proposed case is an application where a logscale of the t axis makes sense. Without this option, one has to define an additional log-scaling function as a workaround. Meanwhile, the logscale of the t axis is not necessarily related to the logscale of another axis (like x1). Therefore, I would plead for

    • set log t as an allowed command
    • not correlate the log t with logscale of x by default - for this purpose, the plot '+' option is the far better approach
     
  • Ethan Merritt

    Ethan Merritt - 2018-09-28
    • status: open --> pending-fixed
     
  • Tatsuro MATSUOKA

    Klaus
    I have updateded the develpment snapshot for windows (ver. 5.3).
    New snapshot includes the commits
    [a3b6a0] [9b43ed] the "logscale perturbs sampling on t" bug hit polar plots also

    You can download snapshot windows binary packages from http://www.tatsuromatsuoka.com/gnuplot/Eng/winbin/
    and you can test on your windows PC.

     

    Related

    Commit: [9b43ed]
    Commit: [a3b6a0]


    Last edit: Tatsuro MATSUOKA 2018-10-01
  • Ethan Merritt

    Ethan Merritt - 2018-10-07
    • Status: pending-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB