[SOLVED] gnuplot changing format of calculated variable

Issue

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 !

Solution

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:

enter image description here

Answered By – theozh

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *