Menu

#2272 Severe bug: gnuplot (version 5.2 patchlevel 8) plots user defined function f(x) wrong!

None
closed-not-a-bug
nobody
None
2020-06-04
2020-06-02
Anonymous
No

Severe bug: gnuplot (version 5.2 patchlevel 8) plots user defined function f(x) wrong!
<<gnuplot_bug.zip>></gnuplot_bug.zip>

Depending on the axis scaling setting a user defined function f(x) is plotted wrong.

Example 1 (wrong):
01000_autoscale.plt

f(x), the red line, should start at x=11.6401, in the center of the filled red circle, but the red line starts later.

Example 2 (correct):
01000_xrange_1.plt

If the x axis is limited by “set xrange [0:51.6401]”, the result is correct an f(x) starts at x=11.6401.

Example 3 (correct):
01000_xrange_2.plt

If the x axis is limited by “set xrange [-100:600], the result is correct an f(x) starts at x=11.6401.

Example 4 (wrong):
01000_xrange_3.plt

If the x axis is limited by “set xrange [-200:700]”, the result is wrong, because f(x) starts not in the center of the red filled circle at x=11,6401, but somehow later.

Best regards,
Werner
werner.simbuerger@hppi.de

1 Attachments

Discussion

  • Ethan Merritt

    Ethan Merritt - 2020-06-02

    When you plot a function, what the program does is to generate a set of points along x that sample the requested range, calculate y=f(x) at each of those points, then draw a line connecting the (x,f(x)) points.

    If you zoom in to a very precisely defined x coordinate like x=24.4401 in your example, it is unlikely that one of the samples lies precisely at this x coordinate. For a smooth function this probably does not matter, but for a rapidly varying function you need to make sure that the number of samples is large enough so that there is a sampled point "close enough" to any specific point of interest. The default number of samples is 100.

    For your plots, 100 samples across a small xrange is sufficient that a sampled point lies "close enough" to your point of interest that you call it correct. But 100 samples across a xrange of [-200:700] corresponds to one sample every 10 units on x. This sampling is much too coarse to catch a precise x value like 11.6401. If you really wanted 4 decimal places of precision over a range of 1000, that would require 10 million samples! (clearly not feasible). Fortunately, for the purpose of plotting it is only necessary to sample at a precision appropriate to the visual resolution of the plot. Given that the number of horizontal pixels in a typical image is at most a few thousand, setting

      set sample 2000
    

    should be more than sufficient.

     
  • Ethan Merritt

    Ethan Merritt - 2020-06-02
    • status: open --> open-invalid
    • Group: -->
    • Priority: -->
     
  • Ethan Merritt

    Ethan Merritt - 2020-06-02
    • status: open-invalid --> open-not-a-bug
     
  • Werner Simbuerger

    Thank you Ethan for pointing me to the sample issue.

    set sample 2000
    or
    set samples 2000

    have same effect, and solve the issue.

    In my case f(x) exists only inside the region [0:60]. Therefore, I could restrict the samples command to f(x):

    [0:60] f(x) title "" lw 3 lc rgbcolor "0xED1847" axis x1y1,\

    which also works.

    Probably a gnuplot warning could help, in order to identify potential plot artifacts, if the sampling interval exceeds maybe 1% of the full plot range.

     
  • Ethan Merritt

    Ethan Merritt - 2020-06-04
    • status: open-not-a-bug --> closed-not-a-bug
     

Log in to post a comment.