#637 Fix default numeric formatting to be prettier in enhanced mode

None
closed-accepted
Ethan Merritt
None
5
2014-09-05
2013-10-03
Craig DeForest
No

Gnuplot is notorious among scientists for being "ugly by default" compared to, say, R. This appears to boil down to a few minor formatting issues. The most cogent is formatting of large numbers in axis values.

Even in enhanced terminals, the current CVS produces values like "1.00000e+15" in the default formatting, while R and other packages produce much prettier axis values by default. This patch overcomes that by:

  • introducing new format specifiers -- '%h' and '%H' -- that use "x10^{exp}" and "*10^{exp}" when (and only when) used in enhanced text mode (falling back to %g/%G in non-enhanced text mode);

  • making '% h' the default axis value specifier instead of the former "% g".

Enhanced text mode is tested by looking at the flags for the current terminal. Although some text outputs have ignore_enhanced flags, those text outputs (titles and legends) do not use gprintf for their formatting, so the current mod does not have to examine those flags nor know its context in order to work.

1 Attachments

Related

Patches: #637

Discussion

  • Ethan Merritt
    Ethan Merritt
    2013-10-04

    Aside from whether or not this should be the default, can you clarify in what ways this differs from placing in your ~/.gnuplot file the lines
    set termopt enhanced
    set format "%tx^{%T}"

    Is the advantage just that it's easier to remember %h than to remember %tx^{%T}?

     
  • Craig DeForest
    Craig DeForest
    2013-10-04

    Yes, certainly. "%tx10^{$T}" is a pretty printed version of "%f" printf-style formatting. What is needed is a pretty printed version of "%g" printf-style formatting (that uses conventional notation or scientific notation as appropriate). The powers of 10 -6..+6 with the current %g processing get
    "1e-06","1e-05","0.0001","0.001","0.01","0.1","1","10","100","1000","1e+04","1e+05".

    With %h they get either that sequence (in non-enhanced mode) or
    "1x10^{-6}","1x10^{-5}","0.0001","0.001","0.01","0.1","1","10","100","1000","1x10^{4}","1x10^{5}".

    With the format you specified they'd all get the scientific form.

    On Oct 4, 2013, at 12:36 AM, "Ethan Merritt" sfeam@users.sf.net wrote:

    Aside from whether or not this should be the default, can you clarify in what ways this differs from placing in your ~/.gnuplot file the lines
    set termopt enhanced
    set format "%tx^{%T}"

    Is the advantage just that it's easier to remember %h than to remember %tx^{%T}?

    [patches:#637] Fix default numeric formatting to be prettier in enhanced mode

    Status: open
    Created: Thu Oct 03, 2013 07:56 PM UTC by Craig DeForest
    Last Updated: Thu Oct 03, 2013 07:56 PM UTC
    Owner: Ethan Merritt

    Gnuplot is notorious among scientists for being "ugly by default" compared to, say, R. This appears to boil down to a few minor formatting issues. The most cogent is formatting of large numbers in axis values.
    Even in enhanced terminals, the current CVS produces values like "1.00000e+15" in the default formatting, while R and other packages produce much prettier axis values by default. This patch overcomes that by:

    introducing new format specifiers -- '%h' and '%H' -- that use "x10^{exp}" and "*10^{exp}" when (and only when) used in enhanced text mode (falling back to %g/%G in non-enhanced text mode);

    making '% h' the default axis value specifier instead of the former "% g".

    Enhanced text mode is tested by looking at the flags for the current terminal. Although some text outputs have ignore_enhanced flags, those text outputs (titles and legends) do not use gprintf for their formatting, so the current mod does not have to examine those flags nor know its context in order to work.

    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gnuplot/patches/637/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Patches: #637

  • Ethan Merritt
    Ethan Merritt
    2013-10-04

    I like the idea in principle, but I think there are some glitches to be fixed.

    The patched gnuplot is not behaving quite as you describe. For example, if I run the "histograms" demo after patching I see an odd mixture of exponential notation and lots of zeros in the first plot. Some of the subsequent plots seem to have lost the exponential notation altogether even though the range on Y remains the same. Bugs?

    The "vector" demo fails badly. This turns out to be because the new format is applied when writing to a formatted output file as requested by "set table ...". I'm not sure what the proper fix is for that. Maybe enhanced mode should unconditionally be disabled during "set table", or maybe only during numerical output, or maybe the new format code should test somehow for being inside tabuler output mode.

    Documentation is needed.

    It is not obvious to me what is supposed to happen if I say "set format '%.3h'"

    Would it be possible to combine this with the notion of scientific powere (current format %S")? That is, only use exponents 3, 6, 9, ...

    Could the new format fully address the request in ticket #333 to intelligents suppress trailing zeros?
    https://sourceforge.net/p/gnuplot/feature-requests/333/

    Ethan
    
     
  • Craig DeForest
    Craig DeForest
    2013-10-04

    Hmmm, I think all those things could happen. I'll have a look at the histograms demo, add some logic to suppress trailing zeroes, and think about the set table stuff.

    I'll also poke around the documentation tree to see where that should go...

    (mobile)

    On Oct 4, 2013, at 11:29 AM, "Ethan Merritt" sfeam@users.sf.net wrote:

    I like the idea in principle, but I think there are some glitches to be fixed.

    The patched gnuplot is not behaving quite as you describe. For example, if I run the "histograms" demo after patching I see an odd mixture of exponential notation and lots of zeros in the first plot. Some of the subsequent plots seem to have lost the exponential notation altogether even though the range on Y remains the same. Bugs?

    The "vector" demo fails badly. This turns out to be because the new format is applied when writing to a formatted output file as requested by "set table ...". I'm not sure what the proper fix is for that. Maybe enhanced mode should unconditionally be disabled during "set table", or maybe only during numerical output, or maybe the new format code should test somehow for being inside tabuler output mode.

    Documentation is needed.
    It is not obvious to me what is supposed to happen if I say "set format '%.3h'"

    Would it be possible to combine this with the notion of scientific powere (current format %S")? That is, only use exponents 3, 6, 9, ...

    Could the new format fully address the request in ticket #333 to intelligents suppress trailing zeros?
    https://sourceforge.net/p/gnuplot/feature-requests/333/

    Ethan
    [patches:#637] Fix default numeric formatting to be prettier in enhanced mode

    Status: open
    Created: Thu Oct 03, 2013 07:56 PM UTC by Craig DeForest
    Last Updated: Fri Oct 04, 2013 06:36 AM UTC
    Owner: Ethan Merritt

    Gnuplot is notorious among scientists for being "ugly by default" compared to, say, R. This appears to boil down to a few minor formatting issues. The most cogent is formatting of large numbers in axis values.
    Even in enhanced terminals, the current CVS produces values like "1.00000e+15" in the default formatting, while R and other packages produce much prettier axis values by default. This patch overcomes that by:

    introducing new format specifiers -- '%h' and '%H' -- that use "x10^{exp}" and "*10^{exp}" when (and only when) used in enhanced text mode (falling back to %g/%G in non-enhanced text mode);

    making '% h' the default axis value specifier instead of the former "% g".

    Enhanced text mode is tested by looking at the flags for the current terminal. Although some text outputs have ignore_enhanced flags, those text outputs (titles and legends) do not use gprintf for their formatting, so the current mod does not have to examine those flags nor know its context in order to work.

    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gnuplot/patches/637/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Patches: #637

  • Ethan Merritt
    Ethan Merritt
    2013-10-05

    In thinking about this some more, I've decided that for me the "ugliness" is largely due to the inconsistent formatting of tic labels along the same axis. The first plot of the histograms demo is a good example of this. Both the current " %g" and the " %t" of your patch suffer from the problem that the decision on whether to use an exponent and how many character positions to devote to the mantissa are made all over again for each tic label. I think the only way to get consistent formatting is to look at all the tic values first and then pick some single format that can be used for all of them.

     
  • Craig DeForest
    Craig DeForest
    2013-10-05

    OK, here's a modified (v2) patch against current CVS, and also some screen shots of the histogram demo with and without. The first one shows the first screen, with the scientific-notation labels from %g converted to pretty exponents. The second shows the second screen, with the non-scientific-notation labels left unchanged.

    On Oct 4, 2013, at 10:50 PM, "Ethan Merritt" sfeam@users.sf.net wrote:

    In thinking about this some more, I've decided that for me the "ugliness" is largely due to the inconsistent formatting of tic labels along the same axis. The first plot of the histograms demo is a good example of this. Both the current " %g" and the " %t" of your patch suffer from the problem that the decision on whether to use an exponent and how many character positions to devote to the mantissa are made all over again for each tic label. I think the only way to get consistent formatting is to look at all the tic values first and then pick some single format that can be used for all of them.

    [patches:#637] Fix default numeric formatting to be prettier in enhanced mode

    Status: open
    Created: Thu Oct 03, 2013 07:56 PM UTC by Craig DeForest
    Last Updated: Fri Oct 04, 2013 05:29 PM UTC
    Owner: Ethan Merritt

    Gnuplot is notorious among scientists for being "ugly by default" compared to, say, R. This appears to boil down to a few minor formatting issues. The most cogent is formatting of large numbers in axis values.
    Even in enhanced terminals, the current CVS produces values like "1.00000e+15" in the default formatting, while R and other packages produce much prettier axis values by default. This patch overcomes that by:

    introducing new format specifiers -- '%h' and '%H' -- that use "x10^{exp}" and "*10^{exp}" when (and only when) used in enhanced text mode (falling back to %g/%G in non-enhanced text mode);

    making '% h' the default axis value specifier instead of the former "% g".

    Enhanced text mode is tested by looking at the flags for the current terminal. Although some text outputs have ignore_enhanced flags, those text outputs (titles and legends) do not use gprintf for their formatting, so the current mod does not have to examine those flags nor know its context in order to work.

    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gnuplot/patches/637/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Patches: #637

  • Craig DeForest
    Craig DeForest
    2013-10-05

    :-)

    For the past half-hour or so I've actually been trying to track down your issues with the various plots, and I've been unable to reproduce 'em - I was about to ask you for more detail.

    I did add some logic to the other axis label formats ("%e", etc.) that deletes trailing zeroes unless a precision specifier is given -- so, e.g., "%e" yields "1e+05" and "1.2e+05" while "%.1e" yields "1.0e+05" and "1.2e+05", and "%.3e" gives "1.000e+05" and "1.200e+05".

    I went after the %h formatting specifically because I find myself writing stuff like that all the time -- generating large custom axis lists to get my "0.01" and "0.1" next to "10^{-3}" and such.

    My hope is that those who like variable formatting (as do I, for quick plotting) can have it, without falling back to the ugliness of the m.mmmmmE+ee notation in pretty terminals, or having to gin up custom tic tables.

    Stand by a moment, I'll send an updated patch around, with some screen shots.

    On Oct 4, 2013, at 10:50 PM, "Ethan Merritt" sfeam@users.sf.net wrote:

    In thinking about this some more, I've decided that for me the "ugliness" is largely due to the inconsistent formatting of tic labels along the same axis. The first plot of the histograms demo is a good example of this. Both the current " %g" and the " %t" of your patch suffer from the problem that the decision on whether to use an exponent and how many character positions to devote to the mantissa are made all over again for each tic label. I think the only way to get consistent formatting is to look at all the tic values first and then pick some single format that can be used for all of them.

    [patches:#637] Fix default numeric formatting to be prettier in enhanced mode

    Status: open
    Created: Thu Oct 03, 2013 07:56 PM UTC by Craig DeForest
    Last Updated: Fri Oct 04, 2013 05:29 PM UTC
    Owner: Ethan Merritt

    Gnuplot is notorious among scientists for being "ugly by default" compared to, say, R. This appears to boil down to a few minor formatting issues. The most cogent is formatting of large numbers in axis values.
    Even in enhanced terminals, the current CVS produces values like "1.00000e+15" in the default formatting, while R and other packages produce much prettier axis values by default. This patch overcomes that by:

    introducing new format specifiers -- '%h' and '%H' -- that use "x10^{exp}" and "*10^{exp}" when (and only when) used in enhanced text mode (falling back to %g/%G in non-enhanced text mode);

    making '% h' the default axis value specifier instead of the former "% g".

    Enhanced text mode is tested by looking at the flags for the current terminal. Although some text outputs have ignore_enhanced flags, those text outputs (titles and legends) do not use gprintf for their formatting, so the current mod does not have to examine those flags nor know its context in order to work.

    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gnuplot/patches/637/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Patches: #637

  • Ethan Merritt
    Ethan Merritt
    2013-10-07

    I have added a modified version of your patch to the development tree in CVS. The modifications are
    1) Apply the equivalent markup for LaTeX terminals
    2) The default format for LaTeX is "$%h$"
    3) Fall back to %g for tabular output

    In order that the new default formats are applied more often, I plan to make enhanced text mode the default state for terminals that support it.

     
  • Ethan Merritt
    Ethan Merritt
    2013-10-07

    • status: open --> pending-accepted
    • Group: -->
     
  • Craig DeForest
    Craig DeForest
    2013-10-07

    Thanks, Ethan!

    On Oct 7, 2013, at 3:08 PM, Ethan Merritt sfeam@users.sf.net wrote:

    status: open --> pending-accepted
    Group: -->
    [patches:#637] Fix default numeric formatting to be prettier in enhanced mode

    Status: pending-accepted
    Created: Thu Oct 03, 2013 07:56 PM UTC by Craig DeForest
    Last Updated: Mon Oct 07, 2013 09:08 PM UTC
    Owner: Ethan Merritt

    Gnuplot is notorious among scientists for being "ugly by default" compared to, say, R. This appears to boil down to a few minor formatting issues. The most cogent is formatting of large numbers in axis values.
    Even in enhanced terminals, the current CVS produces values like "1.00000e+15" in the default formatting, while R and other packages produce much prettier axis values by default. This patch overcomes that by:

    introducing new format specifiers -- '%h' and '%H' -- that use "x10^{exp}" and "*10^{exp}" when (and only when) used in enhanced text mode (falling back to %g/%G in non-enhanced text mode);

    making '% h' the default axis value specifier instead of the former "% g".

    Enhanced text mode is tested by looking at the flags for the current terminal. Although some text outputs have ignore_enhanced flags, those text outputs (titles and legends) do not use gprintf for their formatting, so the current mod does not have to examine those flags nor know its context in order to work.

    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gnuplot/patches/637/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Patches: #637

  • Ethan Merritt
    Ethan Merritt
    2014-02-17

    • status: pending-accepted --> closed-accepted