genesi5
genesi5

Reputation: 453

Gnuplot format converting, bytes

For example, i've got ammount of bytes, some of them equals to gigabytes.

The current formatting setup set format y "%.2s%cb does this:

1.20G
1.00G
800.00M
600.00M
.....
0

I need to convert ytics in the way to show only three digits, or/and mainly in one scientific power:

1.00G
0.80G
0.60G
....
0

How can i do that?

Upvotes: 1

Views: 514

Answers (1)

Christoph
Christoph

Reputation: 48420

Then you cannot use gnuplot's automatic formatting. If you know, that the data must be shown in Gigabytes, then use

set format y "%.2fG"
plot 'data.dat' using 1:($2/1e9)

This assumes, that the data in the second column is given in bytes.

If you want to stick to the largest scientific power, you can first determine the maximum value with stats and then calculate the scientific power:

stats 'data.dat' using 2 nooutput
scientific_power_index = ceil(log10(STATS_max)/3)
scientific_power = word("'' k M G T", scientific_power_index)
scale = 10**((scientific_power_index - 1) * -3)

set format y "%.2f".scientific_power
plot 'data.dat' using 1:($2 * scale)

Note, that this as such works only with gnuplot 5, and it doesn't work properly if the maximum y-value has a different scientific power then the autoscaled maximum y-value (e.g. max value 990e6 -> autoscaling takes 1e9, but the code above would still give 'M' as scientific power).

Upvotes: 1

Related Questions