Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #3994 > unrolled thread

space between sign and digit

Started byJörg Buchholz <bookwood4new@freenet.de>
First post2018-07-11 08:52 +0200
Last post2018-07-12 07:21 +0200
Articles 9 — 3 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  space between sign and digit Jörg Buchholz <bookwood4new@freenet.de> - 2018-07-11 08:52 +0200
    Re: space between sign and digit Karl Ratzsch <mail.kfr@gmx.net> - 2018-07-11 10:00 +0200
      Re: space between sign and digit Jörg Buchholz <bookwood4new@freenet.de> - 2018-07-11 14:16 +0200
        Re: space between sign and digit Karl Ratzsch <mail.kfr@gmx.net> - 2018-07-11 15:16 +0200
          Re: space between sign and digit Jörg Buchholz <bookwood4new@freenet.de> - 2018-07-12 07:36 +0200
            Re: space between sign and digit Karl Ratzsch <mail.kfr@gmx.net> - 2018-07-12 20:42 +0200
    Re: space between sign and digit Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2018-07-11 20:06 +0200
      Re: space between sign and digit Karl Ratzsch <mail.kfr@gmx.net> - 2018-07-12 06:53 +0200
      Re: space between sign and digit Jörg Buchholz <bookwood4new@freenet.de> - 2018-07-12 07:21 +0200

#3994 — space between sign and digit

FromJörg Buchholz <bookwood4new@freenet.de>
Date2018-07-11 08:52 +0200
Subjectspace between sign and digit
Message-ID<pi49eq$a7$1@dont-email.me>
Hello,

I would like to print a function in the key like this:

f11(x) = -2.56·x - 103.63

I use the following code in the plot command for that:

f11(x) lt 2 lw 4 dt 4 t sprintf("f11(x) =%6.2f·x%+7.2f",a,b11)

That means, that I use the sign from the format specifier as plus sign
or minus sing in the printed function. But than I don't have a space in
front of the second number. The second number can be positive or negative.

Jörg

[toc] | [next] | [standalone]


#3996

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2018-07-11 10:00 +0200
Message-ID<pi4dfb$rk4$1@solani.org>
In reply to#3994
Am 11.07.2018 um 08:52 schrieb Jörg Buchholz:
> Hello,
> 
> I would like to print a function in the key like this:
> 
> f11(x) = -2.56·x - 103.63
> 
> I use the following code in the plot command for that:
> 
> f11(x) lt 2 lw 4 dt 4 t sprintf("f11(x) =%6.2f·x%+7.2f",a,b11)
> 
> That means, that I use the sign from the format specifier as plus sign
> or minus sing in the printed function. But than I don't have a space in
> front of the second number. The second number can be positive or negative.

sprintf() can't add an extra space in there i think. Following uses the
ternary operator on b11 to check which sign character is needed

plot f11(x) lt 2 lw 4 dt 4 t \
  sprintf("f11(x) =%.2f·x %s %.2f",a,b11<0?"-":"+",abs(b11))

[toc] | [prev] | [next] | [standalone]


#3998

FromJörg Buchholz <bookwood4new@freenet.de>
Date2018-07-11 14:16 +0200
Message-ID<pi4seh$66s$1@dont-email.me>
In reply to#3996
On 11.07.2018 10:00, Karl Ratzsch wrote:
> Am 11.07.2018 um 08:52 schrieb Jörg Buchholz:
>> Hello,
>>
>> I would like to print a function in the key like this:
>>
>> f11(x) = -2.56·x - 103.63
>>
>> I use the following code in the plot command for that:
>>
>> f11(x) lt 2 lw 4 dt 4 t sprintf("f11(x) =%6.2f·x%+7.2f",a,b11)
>>
>> That means, that I use the sign from the format specifier as plus sign
>> or minus sing in the printed function. But than I don't have a space in
>> front of the second number. The second number can be positive or negative.
> 
> sprintf() can't add an extra space in there i think. Following uses the
> ternary operator on b11 to check which sign character is needed
> 
> plot f11(x) lt 2 lw 4 dt 4 t \
>   sprintf("f11(x) =%.2f·x %s %.2f",a,b11<0?"-":"+",abs(b11))
>


Interesting solution. On more complex functions the code is a bit long.
But on the other hand I can use a thin space for better looking at the
print out.

Thanks

Jörg

[toc] | [prev] | [next] | [standalone]


#3999

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2018-07-11 15:16 +0200
Message-ID<pi4vvj$8k6$1@solani.org>
In reply to#3998
Am 11.07.2018 um 14:16 schrieb Jörg Buchholz:
> On 11.07.2018 10:00, Karl Ratzsch wrote:
>> plot f11(x) lt 2 lw 4 dt 4 t \
>>   sprintf("f11(x) =%.2f·x %s %.2f",a,b11<0?"-":"+",abs(b11))
>>
> 
> Interesting solution. On more complex functions the code is a bit long.

You're welcome. ;-) This looks a bit nicer

  nstr(x) = sprintf("%s %.2f",x<0?"-":"+",abs(x)) # return string with a
space between sign and number

  plot f11(x) title sprintf("f11(x) =%.2f·x %s",a,nstr(b11))

or you can even outsource the whole sprintf() call into a function

  tstr(n,a,b) = sprintf("%s = %.2f·x %s %.2f",n,a,b<0?"-":"+",abs(b))

  plot f11(x) title tstr("f11(x)",a,b11)

so your plot command stays readable.

[toc] | [prev] | [next] | [standalone]


#4003

FromJörg Buchholz <bookwood4new@freenet.de>
Date2018-07-12 07:36 +0200
Message-ID<pi6pc1$ne4$1@dont-email.me>
In reply to#3999
On 11.07.2018 15:16, Karl Ratzsch wrote:
> Am 11.07.2018 um 14:16 schrieb Jörg Buchholz:
>> On 11.07.2018 10:00, Karl Ratzsch wrote:
>>> plot f11(x) lt 2 lw 4 dt 4 t \
>>>   sprintf("f11(x) =%.2f·x %s %.2f",a,b11<0?"-":"+",abs(b11))
>>>
>>
>> Interesting solution. On more complex functions the code is a bit long.
> 
> You're welcome. ;-) This looks a bit nicer
> 
>   nstr(x) = sprintf("%s %.2f",x<0?"-":"+",abs(x)) # return string with a
> space between sign and number
> 
>   plot f11(x) title sprintf("f11(x) =%.2f·x %s",a,nstr(b11))
> 
> or you can even outsource the whole sprintf() call into a function
> 
>   tstr(n,a,b) = sprintf("%s = %.2f·x %s %.2f",n,a,b<0?"-":"+",abs(b))
> 
>   plot f11(x) title tstr("f11(x)",a,b11)
> 
> so your plot command stays readable.

It is the right direction, something like a "newcommand" in LaTex that
makes the daily work easier.

But I need the %.2f variable, cause sometimes there are numbers which
needs more or less digits after the floating point.

At the moment I keep at the long version.

Thanks for helping.

Jörg

[toc] | [prev] | [next] | [standalone]


#4008

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2018-07-12 20:42 +0200
Message-ID<pi87ef$aee$1@solani.org>
In reply to#4003
Am 12.07.2018 um 07:36 schrieb Jörg Buchholz:
> On 11.07.2018 15:16, Karl Ratzsch wrote:
>> Am 11.07.2018 um 14:16 schrieb Jörg Buchholz:
>>> On 11.07.2018 10:00, Karl Ratzsch wrote:
>>>> plot f11(x) lt 2 lw 4 dt 4 t \
>>>>   sprintf("f11(x) =%.2f·x %s %.2f",a,b11<0?"-":"+",abs(b11))
>>>>
>>>
>>> Interesting solution. On more complex functions the code is a bit long.
>>
>> You're welcome. ;-) This looks a bit nicer
>>
>>   nstr(x) = sprintf("%s %.2f",x<0?"-":"+",abs(x)) # return string with a
>> space between sign and number
>>
>>   plot f11(x) title sprintf("f11(x) =%.2f·x %s",a,nstr(b11))
>>
>> or you can even outsource the whole sprintf() call into a function
>>
>>   tstr(n,a,b) = sprintf("%s = %.2f·x %s %.2f",n,a,b<0?"-":"+",abs(b))
>>
>>   plot f11(x) title tstr("f11(x)",a,b11)
>>
>> so your plot command stays readable.
> 
> It is the right direction, something like a "newcommand" in LaTex that
> makes the daily work easier.
> 
> But I need the %.2f variable, cause sometimes there are numbers which
> needs more or less digits after the floating point.

That's something missing in sprintf(), a way to give the overall
number of significant digits for fp output. You can of course use
exponential notation.

Or write a function that uses sprintf() to construct a customised
format string for another sprintf() function call.

  #syntax tstr(fnamstr,a,b,b_ndecimals)
  tstr(n,a,b,bs) = sprintf("%s = %.2f·x %s
%.".sprintf("%.f",bs)."f",n,a,b<0?"-":"+",abs(b))

 ;-)

[toc] | [prev] | [next] | [standalone]


#4000

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2018-07-11 20:06 +0200
Message-ID<fqmv8hFmg36U1@mid.dfncis.de>
In reply to#3994
Am 11.07.2018 um 08:52 schrieb Jörg Buchholz:
> I would like to print a function in the key like this:
> 
> f11(x) = -2.56·x - 103.63
> 
> I use the following code in the plot command for that:
> 
> f11(x) lt 2 lw 4 dt 4 t sprintf("f11(x) =%6.2f·x%+7.2f",a,b11)
> 
> That means, that I use the sign from the format specifier as plus sign
> or minus sing in the printed function. But than I don't have a space in
> front of the second number. The second number can be positive or negative.

So what's so wrong with the simple

	sprintf("f11(x) = %6.2f·x + % 7.2f",a,b11)
	
?  Yes, that means for negative bl1 you'll get "+ -103.63", but is that 
really such a problem?

[toc] | [prev] | [next] | [standalone]


#4001

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2018-07-12 06:53 +0200
Message-ID<pi6mrl$a76$1@solani.org>
In reply to#4000
Am 11.07.2018 um 20:06 schrieb Hans-Bernhard Bröker:
> Am 11.07.2018 um 08:52 schrieb Jörg Buchholz:
>> I would like to print a function in the key like this:
>>
>> f11(x) = -2.56·x - 103.63
>>
>> I use the following code in the plot command for that:
>>
>> f11(x) lt 2 lw 4 dt 4 t sprintf("f11(x) =%6.2f·x%+7.2f",a,b11)
>>
>> That means, that I use the sign from the format specifier as plus
>> sign
>> or minus sing in the printed function. But than I don't have a
>> space in
>> front of the second number. The second number can be positive or
>> negative.
> 
> So what's so wrong with the simple
> 
>     sprintf("f11(x) = %6.2f·x + % 7.2f",a,b11)
>     
> ?  Yes, that means for negative bl1 you'll get "+ -103.63", but is
> that really such a problem?

Probably a matter of taste. ;-)

[toc] | [prev] | [next] | [standalone]


#4002

FromJörg Buchholz <bookwood4new@freenet.de>
Date2018-07-12 07:21 +0200
Message-ID<pi6oh1$jor$1@dont-email.me>
In reply to#4000
On 11.07.2018 20:06, Hans-Bernhard Bröker wrote:
> Am 11.07.2018 um 08:52 schrieb Jörg Buchholz:
>> I would like to print a function in the key like this:
>>
>> f11(x) = -2.56·x - 103.63
>>
>> I use the following code in the plot command for that:
>>
>> f11(x) lt 2 lw 4 dt 4 t sprintf("f11(x) =%6.2f·x%+7.2f",a,b11)
>>
>> That means, that I use the sign from the format specifier as plus sign
>> or minus sing in the printed function. But than I don't have a space in
>> front of the second number. The second number can be positive or
>> negative.
> 
> So what's so wrong with the simple
> 
>     sprintf("f11(x) = %6.2f·x + % 7.2f",a,b11)
>     
> ?  Yes, that means for negative bl1 you'll get "+ -103.63", but is that
> really such a problem?

If I done the graph just for me it is no problem. If I give the graph to
other people in this region sometimes they say it looks odd. So it is
like Karl says, it is only a appearance problem not a really problem.

Jörg

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web