I have this code in gnuplot to plot the mean.
The problem is that the value is very low like 0.00000000000000001. I woul like to plot it in scientific notation, but i have this error if i try to follow the set format guide.
Thank you! Code that I have:
stats filename u ($1*$2):2 nooutput
mean = STATS_sum_x/STATS_sum_y
set arrow 1 from mean, graph 0 to mean, graph 1 nohead lw 2 lc rgb "red" front
set label 1 sprintf("Mean: %8.6f", mean) at mean, graph 1 offset 1,-0.7
Code if I try to have scientific notation:
stats filename u ($1*$2):2 nooutput
mean = STATS_sum_x/STATS_sum_y
set arrow 1 from mean, graph 0 to mean, graph 1 nohead lw 2 lc rgb "red" front
set label 1 sprintf("Mean: %s*10^{%S}", mean) at mean, graph 1 offset 1,-0.7
Error:
f_sprintf: attempt to print numeric value with string format
Thank you !
CodePudding user response:
I am also a bit confused about the documentation for help format_specifiers.
Check help gprintf and try using gprintf() instead of sprintf(). Maybe the following is using %h is also fine for you.
Code:
reset session
mean = 0.00000000000000001 # or 1e-17
set label 1 gprintf("Mean: %h", mean)
plot x
Result:
CodePudding user response:
@theozh gave you the correct answer, I'd just like to expand a bit on that. If you want to enhance the appearance of the label, you might want to replace the x with a × and the hyphen with a proper minus sign. Then you can create your own custom label with by using %t and %T:
set encoding utf8
set minussign
a=1e-17
set label 1 gprintf("Mean: %.0t × 10^{%T}", a)
plot sin(x)
If you plan on using LaTeX you might of course as well use LaTeX code instead.


