0

I have a csv file includes two column

no. of packet   size 
1               60 
2               70 
3              400
4              700
.
.
.
1000000         60

where the first column is

the number of packet

, and the second column is

the size of packet in bytes.

the total number of packets in the csv file is one million. I need to plot histogram for this data file by:

xrange = [0, 5 , 10 , 15 ] 

which denotes the packet size in bytes. The range [0] denotes the packet size less than 100 bytes, and [5] denotes the packet bytes less than 500 bytes and so on.

yrange = [ 10, 100, 10000, 100000000], 

which denots the number of packets

Any help will be highly appreciated.

2 Answers 2

1

Don't quite remember exactly how this works, but the commands given in my Gnuplot in Action book for creating a histogram are

bin(x,s) = s*int(x/s)
plot "data-file" using (bin(1,0.1)):(1./(0.1*300)) smooth frequency with boxes

I believe smooth frequency is the command that's important to you, and you need to figure out what the using argument should be (possibly with a different function used).

Sign up to request clarification or add additional context in comments.

1 Comment

Brad Richardson... Thank you, i have download this book and i will read the code
1

This should do the job:

# binning function for arbitrary ranges, change as needed
bin(x) = x<100 ? 0 : x<500 ? 5 : x<2500 ? 10 : 15 

# every occurence is counted as (1)
plot datafile using (bin($2)):(1) smooth freq with boxes

Im not really sure what you mean by "yrange [10 100 1000 ...]", do you want a logscaled ordinate?

Then just

set xrange [1:1e6]
set logscale y

before plotting.

5 Comments

Karl Ratzsch... The [y] values in the output graph denote the number of packet from 1 to one million
Karl Ratzsch... when i implemented you code above, i got this message error invalid expression for the line code bin(x) = x<100 ? 0 : x<500 ? 5 : x<2500 ? 10 : 15
can't be, i just pasted it into the gnuplot console and it worked as expected. Check "help ternary operator" to see how the function works.
Karl Ratzsch... Thank you for your help .
You're welcome. Btw., if you ask a gnuplot question, you should stick to the gnuplot syntax. Your range specifiers e.g. are very obscure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.