string - suffix notation in gnuplot kilo mega mili micro nano pico -


i know how use suffix notation in gnuplot axis :

set ytics format "%.1s%c" 

howver not taken account in sprintf ...

gnuplot> pr sprintf("%s", 2e+3)      f_sprintf: attempt print numeric value string format 

so made own function :

suffixnotation(x)=sprintf("%g%s",\ (x>=1e+9&&x<1e+12 ) ? x*1e-9 :\ (x>=1e+6&&x<1e+9 ) ? x*1e-6 :\ (x>=1e+3&&x<1e+6 ) ? x*1e-3 :\ (x>=1e-3&&x<1    ) ? x*1e+3 :\ (x>=1e-6&&x<1e-3 ) ? x*1e+6 :\ (x>=1e-9&&x<1e-6 ) ? x*1e+9 :\ (x>=1e-12&&x<1e-9) ? x*1e+12 : x\ ,\ (x>=1e+6&&x<1e+12 ) ? "g" :\ (x>=1e+6&&x<1e+9 ) ? "m" :\ (x>=1e+3&&x<1e+6 ) ? "k" :\ (x>=1e-3&&x<1    ) ? "u" :\ (x>=1e-6&&x<1e-3 ) ? "n" :\ (x>=1e-9&&x<1e-6 ) ? "p" :\ (x>=1e-12&&x<1e-9) ? "f" : ""\ )  # gnuplot> i=4.321e-13 ; while (i<10e6) { pr suffixnotation(i); i=i*10;} # 4.321e-13 4.321f 43.21f 432.1f 4.321p 43.21p 432.1p 4.321n 43.21n 432.1n 4.321u 43.21u 432.1u 4.321 43.21 432.1 4.321k 43.21k 432.1k 4.321g 

question 1 ? knows if function exist in gnuplot ?

question 2 ? planned gnuplot developer add in sprintf ?

question 3 ? how handle 'package' in gnuplot load("$gnuplotpath/suffixnotation.gp"), mean properly.

gnuplot provides own formatting function gprintf supports these gnuplot-specific format specifiers

print gprintf('%.1s%c', 2e+3) 

prints

2.0k 

quoting official documentation:

the string function gprintf("format", x) uses gnuplot's own format specifiers, gnuplot commands set format, set timestamp, , others. these format specifiers not same used standard c-language routine sprintf(). gprintf() accepts single variable formatted.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -