Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #2942 > unrolled thread

auto caluclation for data display

Started bySyed Jahanzaib <aacable79@gmail.com>
First post2015-06-18 05:01 -0700
Last post2015-06-23 08:53 +0200
Articles 9 — 4 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  auto caluclation for data display Syed Jahanzaib <aacable79@gmail.com> - 2015-06-18 05:01 -0700
    Re: auto caluclation for data display Jörg Buchholz <bookwood4new@freenet.de> - 2015-06-18 21:40 +0200
      Re: auto caluclation for data display Jörg Buchholz <bookwood4new@freenet.de> - 2015-06-22 09:06 +0200
        Re: auto caluclation for data display Karl Ratzsch <mail.kfr@gmx.net> - 2015-06-22 15:19 +0200
          Re: auto caluclation for data display Jörg Buchholz <bookwood4new@freenet.de> - 2015-06-22 19:08 +0200
            Re: auto caluclation for data display Karl Ratzsch <mail.kfr@gmx.net> - 2015-06-22 22:47 +0200
              Re: auto caluclation for data display Karl Ratzsch <mail.kfr@gmx.net> - 2015-06-22 22:58 +0200
            Re: auto caluclation for data display Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2015-06-22 22:54 +0200
              Re: auto caluclation for data display Jörg Buchholz <bookwood4new@freenet.de> - 2015-06-23 08:53 +0200

#2942 — auto caluclation for data display

FromSyed Jahanzaib <aacable79@gmail.com>
Date2015-06-18 05:01 -0700
Subjectauto caluclation for data display
Message-ID<94ad6511-e08e-4e88-87b3-df6b6f6ff876@googlegroups.com>
greetings all,

I am graphing downloads for the user account, but issue is the divide forumla. Is there any method in which gnuplot can auto measure the data like if its in KB , it should it in KB, if its in MB, it should show MB, if its in GB it should GB or vise verse for TB.

at a  moment I am dividing the formula like /1024/1024 to get data in GB which have issue that if data is less then GB, it shows 0.xxx 

[toc] | [next] | [standalone]


#2944

FromJörg Buchholz <bookwood4new@freenet.de>
Date2015-06-18 21:40 +0200
Message-ID<mlv6o7$6hf$1@dont-email.me>
In reply to#2942
On 18.06.2015 14:01, Syed Jahanzaib wrote:
> greetings all,
>
> I am graphing downloads for the user account, but issue is the divide
> forumla. Is there any method in which gnuplot can auto measure the
> data like if its in KB , it should it in KB, if its in MB, it should
> show MB, if its in GB it should GB or vise verse for TB.

Do you want it for ploting labels at the bars or as ylabel? I think 
there is only one ylabel for one graph.

> at a  moment I am dividing the formula like /1024/1024 to get data in
> GB which have issue that if data is less then GB, it shows 0.xxx

If you need to scale the whole yaxis you can first use the stats command 
to get the maximum of your data.

stats "data.txt" u 1:2
max_y = STATS_max_y

This give you the maximum of column 2 into the variable "max_y"

Than you can work with "if" and "else".
if max_y > a than
	set ylabel 'GB'
	plot "data.txt" u 1:($2/1024/1024)
else{If max_y > b than
	set ylabel 'MB'
	plot "data.txt" u 1:($2/1024)
	else set ylabel 'KB'
	plot "data.txt" u 1:2}

This not the real code for gnuplot, it is only a way to do something 
like you want. For including TB, you need a 4 step "if/else" argument.


Jörg

[toc] | [prev] | [next] | [standalone]


#2947

FromJörg Buchholz <bookwood4new@freenet.de>
Date2015-06-22 09:06 +0200
Message-ID<mm8c4v$iqg$1@newsserver.rrzn.uni-hannover.de>
In reply to#2944
On 18.06.2015 21:40, Jörg Buchholz wrote:
> On 18.06.2015 14:01, Syed Jahanzaib wrote:
>> greetings all,
>>
>> I am graphing downloads for the user account, but issue is the divide
>> forumla. Is there any method in which gnuplot can auto measure the
>> data like if its in KB , it should it in KB, if its in MB, it should
>> show MB, if its in GB it should GB or vise verse for TB.
>
> Do you want it for ploting labels at the bars or as ylabel? I think
> there is only one ylabel for one graph.
>
>> at a  moment I am dividing the formula like /1024/1024 to get data in
>> GB which have issue that if data is less then GB, it shows 0.xxx
>
> If you need to scale the whole yaxis you can first use the stats command
> to get the maximum of your data.
>
> stats "data.txt" u 1:2
> max_y = STATS_max_y
>
> This give you the maximum of column 2 into the variable "max_y"
>
> Than you can work with "if" and "else".
> if max_y > a than
>      set ylabel 'GB'
>      plot "data.txt" u 1:($2/1024/1024)
> else{If max_y > b than
>      set ylabel 'MB'
>      plot "data.txt" u 1:($2/1024)
>      else set ylabel 'KB'
>      plot "data.txt" u 1:2}
>
> This not the real code for gnuplot, it is only a way to do something
> like you want. For including TB, you need a 4 step "if/else" argument.

I have done a test and it seems that this works for GB, MB an KB.

stats "data.txt" u 1:2
...
...
...
if (STATS_max_y >= (1024*1024)) {
     set ylabel "Data Downloaded in GB"
     plot "data.txt" using 1:($2/1024/1024) with impulse title "Daily 
Usage" lw 10,\
     "data.txt" using 1:($2/1024/1024):(sprintf("%.0f",$2/1024/1024)) 
with labels offset 0,1
     } else {
     if (STATS_max_y >= 1024) {
     set ylabel "Data Downloaded in MB"
     plot "data.txt" using 1:($2/1024) with impulse title "Daily Usage" 
lw 10,\
     "data.txt" using 1:($2/1024):(sprintf("%.0f",$2/1024)) with labels 
offset 0,1
     } else {
     set ylabel "Data Downloaded in KB"
     plot "data.txt" using 1:2 with impulse title "Daily Usage" lw 10,\
     "data.txt" using 1:2:(sprintf("%.0f",$2)) with labels offset 0,1
     }}

The stats command must be done before you set the xdata to time format.

Jörg

[toc] | [prev] | [next] | [standalone]


#2948

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2015-06-22 15:19 +0200
Message-ID<mm9208$q3t$2@solani.org>
In reply to#2947
Am 22.06.2015 um 09:06 schrieb Jörg Buchholz:
> On 18.06.2015 21:40, Jörg Buchholz wrote:
>> On 18.06.2015 14:01, Syed Jahanzaib wrote:
> ...
> if (STATS_max_y >= (1024*1024)) {
>      set ylabel "Data Downloaded in GB"
>      plot "data.txt" using 1:($2/1024/1024) with impulse title "Daily 
> Usage" lw 10,\
>      "data.txt" using 1:($2/1024/1024):(sprintf("%.0f",$2/1024/1024)) 
> with labels offset 0,1
>      } else {
>      if (STATS_max_y >= 1024) {
>      set ylabel "Data Downloaded in MB"
>      plot "data.txt" using 1:($2/1024) with impulse title "Daily Usage" 
> lw 10,\
>      "data.txt" using 1:($2/1024):(sprintf("%.0f",$2/1024)) with labels 
> offset 0,1
>      } else {
>      set ylabel "Data Downloaded in KB"
>      plot "data.txt" using 1:2 with impulse title "Daily Usage" lw 10,\
>      "data.txt" using 1:2:(sprintf("%.0f",$2)) with labels offset 0,1
>      }}
> 
> The stats command must be done before you set the xdata to time format.
> 
> Jörg
> 

gnuplot has all the onboard tools to do this in two lines:

set format y "%.b %B"
plot dataf using 1:2: w impulse,\
     dataf using 1:2:(gprintf("%.b %B",$2) w labels

;-)

[toc] | [prev] | [next] | [standalone]


#2949

FromJörg Buchholz <bookwood4new@freenet.de>
Date2015-06-22 19:08 +0200
Message-ID<mm9fbn$stp$1@dont-email.me>
In reply to#2948
On 22.06.2015 15:19, Karl Ratzsch wrote:
> Am 22.06.2015 um 09:06 schrieb Jörg Buchholz:
>> On 18.06.2015 21:40, Jörg Buchholz wrote:
>>> On 18.06.2015 14:01, Syed Jahanzaib wrote:
>> ...
>> if (STATS_max_y >= (1024*1024)) {
>>       set ylabel "Data Downloaded in GB"
>>       plot "data.txt" using 1:($2/1024/1024) with impulse title "Daily
>> Usage" lw 10,\
>>       "data.txt" using 1:($2/1024/1024):(sprintf("%.0f",$2/1024/1024))
>> with labels offset 0,1
>>       } else {
>>       if (STATS_max_y >= 1024) {
>>       set ylabel "Data Downloaded in MB"
>>       plot "data.txt" using 1:($2/1024) with impulse title "Daily Usage"
>> lw 10,\
>>       "data.txt" using 1:($2/1024):(sprintf("%.0f",$2/1024)) with labels
>> offset 0,1
>>       } else {
>>       set ylabel "Data Downloaded in KB"
>>       plot "data.txt" using 1:2 with impulse title "Daily Usage" lw 10,\
>>       "data.txt" using 1:2:(sprintf("%.0f",$2)) with labels offset 0,1
>>       }}
>>
>> The stats command must be done before you set the xdata to time format.
>>
>> Jörg
>>
>
> gnuplot has all the onboard tools to do this in two lines:
>
> set format y "%.b %B"
> plot dataf using 1:2: w impulse,\
>       dataf using 1:2:(gprintf("%.b %B",$2) w labels
>
> ;-)

Some questions to this.
At a simple plot the y-labels are 10ki, 20ki, 29ki ...
Why the step from 20 to 29?
If I use set format y "%.b %BB" I've get 10kiB, 20kiB ....
Is it possible to change the "i"?

the simple data that I used are:
1.0 10250
2.0 34520
3.0 60000
4.0 52360


Kind regards
Jörg

[toc] | [prev] | [next] | [standalone]


#2950

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2015-06-22 22:47 +0200
Message-ID<mm9s9j$tov$1@solani.org>
In reply to#2949
Am 22.06.2015 um 19:08 schrieb Jörg Buchholz:
> On 22.06.2015 15:19, Karl Ratzsch wrote:
>> gnuplot has all the onboard tools to do this in two lines:
>>
>> set format y "%.b %B"
>> plot dataf using 1:2: w impulse,\
>>       dataf using 1:2:(gprintf("%.b %B",$2) w labels
>>
>> ;-)
> 
> Some questions to this.
> At a simple plot the y-labels are 10ki, 20ki, 29ki ...
> Why the step from 20 to 29?
> If I use set format y "%.b %BB" I've get 10kiB, 20kiB ....
> Is it possible to change the "i"?
> 
> the simple data that I used are:
> 1.0 10250
> 2.0 34520
> 3.0 60000
> 4.0 52360
> 

Gnuplot makes tics at 1e4, 2e4 3e4, not on 10*2^10, 20*2^10, etc.

You'll have to set the xtics yourself.

	stats ....
	log2(x) = log(x)/log(2)
	ymax = 2**ceil(log2(stats_max_y))

	set ytics ymax/8

or something similar.

And you cannot get lost of the "i" for binary magitudes. You can use the
format string "%s %c" for kilogramms or computer salespeople's
gigabytes. Which are not gigabytes. ;-)

check "help format specifier"

  Karl

[toc] | [prev] | [next] | [standalone]


#2953

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2015-06-22 22:58 +0200
Message-ID<mm9sua$e4$1@solani.org>
In reply to#2950
Am 22.06.2015 um 22:47 schrieb Karl Ratzsch:
> Am 22.06.2015 um 19:08 schrieb Jörg Buchholz:
>> If I use set format y "%.b %BB" I've get 10kiB, 20kiB ....
>> Is it possible to change the "i"?
.
> 
> ... you cannot get lost of the "i" for binary magitudes. You can use the
> format string "%s %c" for kilogramms or computer salespeople's
> gigabytes. Which are not gigabytes. ;-)


Or, if you really want 1 kByte to be 1024 Bytes, build you own format
function :

fstring(x) = sprintf("%.f ",\
		 x<2**10 ? (ps="",x) :\
 		 x<2**20 ? (ps="Ki", x/2**10) : \
 		 x<2**30 ? (ps="Mi", x/2**20) :\
 		           (ps="Ti", x/2**30)).ps."Byte"

[toc] | [prev] | [next] | [standalone]


#2951

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2015-06-22 22:54 +0200
Message-ID<curavsFend1U1@mid.dfncis.de>
In reply to#2949
Am 22.06.2015 um 19:08 schrieb Jörg Buchholz:

> At a simple plot the y-labels are 10ki, 20ki, 29ki ...
> Why the step from 20 to 29?

Because you selected mismatched options for the axis tic step and the 
tick label format.  One is in powers-of-ten, the other is in powers-of-two.

> If I use set format y "%.b %BB" I've get 10kiB, 20kiB ....
> Is it possible to change the "i"?

No, because omitting it would be wrong.  ISO standard power-of-1024 
prefixes have an 'i' to distinguish them from power-of-1000 prefixes. 
See https://en.wikipedia.org/wiki/Binary_prefix for the details. 
Without them, the output would be just as brutally wrong as all the 
abusers of decimal prefixes for binary powers have been over the years.

Strictly speaking "ki" is wrong, too.  It should be "Ki".

[toc] | [prev] | [next] | [standalone]


#2954

FromJörg Buchholz <bookwood4new@freenet.de>
Date2015-06-23 08:53 +0200
Message-ID<mmavor$c8s$1@newsserver.rrzn.uni-hannover.de>
In reply to#2951
On 22.06.2015 22:54, Hans-Bernhard Bröker wrote:
> Am 22.06.2015 um 19:08 schrieb Jörg Buchholz:
>
>> At a simple plot the y-labels are 10ki, 20ki, 29ki ...
>> Why the step from 20 to 29?
>
> Because you selected mismatched options for the axis tic step and the
> tick label format.  One is in powers-of-ten, the other is in powers-of-two.
>
>> If I use set format y "%.b %BB" I've get 10kiB, 20kiB ....
>> Is it possible to change the "i"?
>
> No, because omitting it would be wrong.  ISO standard power-of-1024
> prefixes have an 'i' to distinguish them from power-of-1000 prefixes.
> See https://en.wikipedia.org/wiki/Binary_prefix for the details. Without
> them, the output would be just as brutally wrong as all the abusers of
> decimal prefixes for binary powers have been over the years.
>
> Strictly speaking "ki" is wrong, too.  It should be "Ki".

Thanks a lot to you and Karl for this informations. Now I have read a 
lot about the Mb and MiB confusion.
If I understand it correct than, if the original data are in byte, than 
data/1024^2 gives me data in MiB and not in MB.

Or say it with "gnuplot"

if (STATS_max_y >= 1024**2) {
set ylabel "Data Downloaded in MiB"
plot "data.txt" using 1:($2/1024**2) with boxes lc "green" title "Daily 
Usage",\
"data.txt" using 1:($2/1024**2):(sprintf("%.0f",$2/1024**2)) with labels 
offset 0,1

is a correct part of my previous "if - else script"

To me the if-else version has more options than use the format-specifers 
%b %B. So I can change the y-label, the color, etc.

Kind regards

Jörg

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web