0

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?

2
  • You can to use gprintf to do this. But just be aware that there is some inconsistency with gprintf() and %t and %T, as point up by @theozh. Commented Feb 22, 2020 at 15:47
  • just saw, print has to be before gprintf. i'll give it a try, thx Commented Feb 22, 2020 at 18:32

1 Answer 1

2

@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
Sign up to request clarification or add additional context in comments.

2 Comments

I didn't check but maybe you have to use the same parameter for %T? since this value doesn't change, they easily misfit?
Do you mean, e.g. %.3T? I don't think so, it wouldn't make too much sense, because power should be an integer number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.