#23 Python like string formating operator %

closed-out-of-date
None
5
2002-07-26
2002-05-03
Anonymous
No

This patch adds a Python like string formating
capability to gnuplot. This is escpecially
usefull to include fitted parameters in plot
titles.

Example:

set title 'Average %.2f' % 123.4567

which is basically useless as you could write

set title 'Average 123.46'

This one is more usefull:

fit a*x+b 'data' via a,b
plot 'data', a*x+b tit '%.2f*x + %%.1f' % (a,b)

The two percent signs %% are a result of the
(not so good) implementation of the formating
operator: The n'th parameter to format needs
2**n percent signes. This is strange but allows
to use %t %l %s and %T %L %S %c in correct
combination.

I find this feature so usefull, that I can easily
live with the complicated syntax, strange clipping,
etc.

Bugs:
set label (and others) limit the resulting
string length to the original one; appending
enough spaces works but justification gets easily
disturbed.
No documentation jet.
Maybe not all strings can be formated.
Including a percent sign in the final string is
complicated.

Volker

Discussion

  • Hans-Bernhard Broeker

    • status: open --> pending-invalid
     
  • Hans-Bernhard Broeker

    • assigned_to: nobody --> broeker
    • status: pending-invalid --> open-invalid
     
  • Hans-Bernhard Broeker

    Logged In: YES
    user_id=27517

    [Actual patch moved over into this report]

    I don't quite think I like the user interface of this at
    all. Even the rather obscure POSIX positional printf()
    syntax (used by tools like GNU gettext, e.g.) is nice
    compared to this.

     
  • Volker Dobler

    Volker Dobler - 2002-05-21

    Logged In: YES
    user_id=533760

    The user interface is realy ugly.
    Maybe something like the Python mapping
    keys for string formating would be more
    readable:

    fit aa*x + bb "data" via aa,bb
    set title "Regression: %(aa).3f * x + %(bb).1f"

    %t %T formating would be easy and %%
    would work the normal way.

    Any comments welcome.

     
  • Hans-Bernhard Broeker

    • status: open-invalid --> closed-out-of-date
     
  • Hans-Bernhard Broeker

    Logged In: YES
    user_id=27517

    I consider this one superseded by patch #559582. I'm closing
    it.

     

Log in to post a comment.