Emanrov
Emanrov

Reputation: 37

gnuplot: using format data types to seperate a number?

I want to seperate the given range of a logarithmic scale, especially the minimum value. e.g. x_min= 0.2 and I want to get "2" and "-1" as parts of 2*10**(-1) for further usage. From manual, that would be %t and %T. I tried using print ("%T", x_min) but I just get x_min itself, no matter which type I set in print. Is there any way to do this in gnuplot?

Upvotes: 0

Views: 77

Answers (1)

theozh
theozh

Reputation: 25749

@GRSousaJR already mentioned some inconsistencies with gprintf() and %t and %T in the comments. I quickly tested with gnuplot 5.2.8, the inconsistencies are still there. A cumbersome solution is given here.

For example:

print gprint("%t",95) gives 0.95 and print gprintf("%T",95) gives 2.

So, 95 = 0.95 x 10^2 is not wrong but the expected result would be 9.5 x 10^1.

But now, if you use for example %.3t instead of %t you will get wrong results. Maybe someone can explain this?!

So in summary: (It's getting a bit lengthy because gprintf() only allows for one parameter.)

Code:

### inconsistency in gprintf with %t and %T
reset session

array Numbers = [0.95, 9.5, 95, 995, 9995]

print "gprintf with %t"
do for [i=1:|Numbers|] {
    print gprintf("% 8g",Numbers[i])." = ".gprintf("%t",Numbers[i])." x 10^".gprintf("%T",Numbers[i])
}
print "gprintf with %.3t"
do for [i=1:|Numbers|] {
    print gprintf("% 8g",Numbers[i])." = ".gprintf("%.3t",Numbers[i])." x 10^".gprintf("%T",Numbers[i])
}
print "gprintf with %.0t"
do for [i=1:|Numbers|] {
    print gprintf("% 8g",Numbers[i])." = ".gprintf("%.0t",Numbers[i])." x 10^".gprintf("%T",Numbers[i])
}
### end of code

Result: (with gnuplot 5.2.8)

gprintf with %t
    0.95 = 9.500000 x 10^-1
     9.5 = 9.500000 x 10^0
      95 = 0.950000 x 10^2    # somehow correct but not the expected result
     995 = 0.995000 x 10^3    # somehow correct but not the expected result
    9995 = 0.999500 x 10^4    # somehow correct but not the expected result
gprintf with %.3t
    0.95 = 9.500 x 10^-1
     9.5 = 9.500 x 10^0
      95 = 9.500 x 10^2    # simply wrong
     995 = 9.950 x 10^3    # simply wrong
    9995 = 9.995 x 10^4    # simply wrong
gprintf with %.0t
    0.95 = 9 x 10^-1
     9.5 = 9 x 10^0
      95 = 1 x 10^2    # somehow ok, rounded. But why not 9 x 10^1, similar to 9.5?
     995 = 1 x 10^3    # ok, rounded
    9995 = 1 x 10^4    # ok, rounded

Upvotes: 2

Related Questions