Mehdi Academic 2014
Mehdi Academic 2014

Reputation: 81

Plotting data using Gnuplot

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.

Upvotes: 0

Views: 250

Answers (2)

Karl
Karl

Reputation: 2187

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.

Upvotes: 1

everythingfunctional
everythingfunctional

Reputation: 871

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).

Upvotes: 1

Related Questions