Question

I have to plot an histogram in logarithmic scale on both axis using gnuplot. I need bins to be equally spaced in log10. Using a logarithmic scale on the y axis isn't a problem. The main problem is creating the bin on the x axis. For example, using 10 bins in log10, first bins will be [1],[2],[3]....[10 - 19][20 - 29].....[100 190] and so on. I've searched on the net but I couldn't find any practical solution. If realizing it in gnuplot is too much complicated could you suggest some other software/language to do it?

As someone asked I will explain more specifically what I need to do. I have a (huge) list like this:

1   14000000
2   7000000
3   6500000
.
.
.
.
6600    1
8900    1
15000   1
19000   1

It shows, for example, that 14 milions of ip addresses have sent 1 packet, 7 milions 2 packets.... 1 ip address have sent 6600 packets, ... , 1 ip address have sent 19000 packets. As you can see the values on both axes are pretty high so I cannot plot it without a logarithmic scale.

The first things I tried because I needed to do it fast was plotting this list as it is with gnuplot setting logscale on both axes using boxes. The result is understandable but not too appropriate. In fact, the boxes became more and more thin going right on the x axis because, obviously, there are more points in 10-100 than in 1-10! So it became a real mess after the second decade.

Was it helpful?

Solution

Have you tried Matplotlib with Python? Matplotlib is a really nice plotting library and when used with Python's simple syntax, you can plot things quite easily:

import matplotlib.pyplot as plot

figure = plot.figure()
axis = figure.add_subplot(1 ,1, 1)
axis.set_yscale('log')

# Rest of plotting code

OTHER TIPS

I tried plotting a histogram with both axis being logarithmically scaled and gnuplot through the error

Log scale on X is incompatible with histogram plots.

So it appears that gnuplot does not support a log scale on the x axis with histograms.

Plotting in log-log scale in GnuPlot is perfectly doable contrary to the other post in this thread.

One can set the log-log scale in GnuPlot with the command set logscale. Then, the assumption is that we have a file with positive (strictly non-zero) values both in the x-axis, as well as the y-axis. For example, the following file is a valid file:

1 0.5
2 0.2
3 0.15
4 0.05

After setting the log-log scale one can plot the file with the command: plot "file.txt" w p where of course file.txt is the name of the file. This command will generate the output with points.

Note also that plotting boxes is tricky and is probably not recommended. One first has to restrict the x-range with a command of the form set xrange [1:4] and only then plot with boxes. Otherwise, when the x-range is undefined an error is returned. I am assuming that in this case plot requires (for appropriate x-values) some boxes to have size log(0), which of course is undefined and hence the error is returned.

Hope it is clear and it will also help others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top