#1263 smooth frequency interacts with logscale y badly

5.0
open
nobody
None
5
2013-07-19
2013-07-19
Matthew
No

I am using gnuplot version 4.4 patchlevel 0 packaged by Debian on Linux.

If I combine the use of "smooth frequency" with "set logscale y", then the smooth frequency part is ignored. For example:

gnuplot> plot 'data' using 1:(1.0) smooth frequency

This plots a graph of value 1 on the x axis with its frequency on the y axis.

gnuplot> set logscale y
gnuplot> replot
Warning: empty y range [1:1], adjusting to [0.99:1.01]

However, this gives the above error message and plots a straight horizontal line with y value 1.0.

Discussion

  • Ethan Merritt
    Ethan Merritt
    2013-07-19

    It is clear why the error message occurs. The "smooth frequency" bit is not ignored, it is applied exactly as requested. For each instance of an x value, log of (1.0) is added to the running total. But the log of (1.0) is 0, so all accumulated totals are also 0 and the y range is necessarily 0. Hence the error message.

    It's less clear why the resulting plot draws a horizontal line at 1 rather than at 0, but I think that's because the program knows that a log scale axis can never reach, or span, 0. So it introduces an offset.

    Requesting instead
    plot 'data' using 1:(exp(1.0)) smooth frequency
    may or may not be what you actually intended. That produces a plot with the correct shape, but again there is a vertical offset introduced. That is arguably a bug, but it's still true that a log scale axis cannot extend to zero it's hard to say what a better alternative would be.

    What were you expecting to happen?

     
  • Matthew
    Matthew
    2013-07-19

    On Fri, 19 Jul 2013, Ethan Merritt wrote:

    It is clear why the error message occurs. The "smooth frequency" bit is not ignored, it is applied exactly as
    requested. For each instance of an x value, log of (1.0) is added to the running total. But the log of (1.0) is 0,
    so all accumulated totals are also 0 and the y range is necessarily 0. Hence the error message.

    I see. Should gnuplot apply the log after doing the smooth, rather than
    before it?

    It's less clear why the resulting plot draws a horizontal line at 1 rather than at 0, but I think that's because
    the program knows that a log scale axis can never reach, or span, 0. So it introduces an offset.

    No, that's obvious. The logged values all sum to 0, which maps to 1 on the
    scale.

    Requesting instead
    plot 'data' using 1:(exp(1.0)) smooth frequency
    may or may not be what you actually intended. That produces a plot with the correct shape, but again there is a
    vertical offset introduced. That is arguably a bug, but it's still true that a log scale axis cannot extend to
    zero it's hard to say what a better alternative would be.

    No, it doesn't produce a plot with the correct shape. What it does is
    produce a graph with the same shape as if "set logscale y" is not set, but
    with different values on the scale.

    Actually, no, what it does with my data is print an error message saying:
    y axis range undefined or overflow
    because gnuplot sums together a whole load of log(exp(1.0)) values, gets a
    reasonable number, defines the (logscale) y range, and then tries to
    convert those numbers to the logscale by calling exp() on them, which
    understandably fails due to overflow.

    What were you expecting to happen?

    I was expecting the y axis to be converted to log scale, and the
    corresponding calculated "smooth frequency" values applied to that scale.
    In other words, the logscale should be applied after the smooth, not
    before.

    Matthew

     
  • Ethan Merritt
    Ethan Merritt
    2013-07-19

    The way log scaling works in gnuplot is that the y value is converted to log(y) at the time the data is read in. In other words, by the time any of the analysis or plotting routines see it, it has already been logged. I think that was a poor choice, but the design goes back to code written more than 25 years ago.

    The development version of gnuplot includes a start at an alternative approach to defining non-linear axes, e.g. "set link x2 via f(x)", but so far it is not complete enough to entirely replace the current log-scale mechanism.

    Anyhow, I can think of one way to achieve what you want using an intermediate file.
    unset log
    set table 'temp.dat'
    plot 'data' using 1:(1) smooth frequency
    unset table
    set log y
    plot 'temp.dat' using 1:2

    Is that a satisfactory solution?