4
votes

I'm using gnuplot in a bash script to draw several things. For this special graphic, I need to print the amount of matrices (y axis) with the matrix size as the x-axis. As the distribution can be pretty sparsed, I want to use a logscale for x and y. It works great with y, but gnuplot tells me I can't have a logscale for the x-axis when I'm using histogram style.

Any ideas to debug this? or on how to present the results using a similar way?

set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set logscale xy
plot '$res/histo-$ld-$lr-$e-$r' using 2:xtic(1) title 'Run'

The error is :

line 0: Log scale on X is incompatible with histogram plots

Thanks in advance.

Edit : btw, I was using gnuplot 4.4 patchlevel 4 and just updated to the newest version (i.e. 4.6 patchlevel 5)

1
Please provide some data samples. Gnuplot histograms work a bit differently from what you might think. The x-axis isn't numeric. In your case the value in the first row, second column is placed at an x-value of 0 with the y-value taken from the second column and a manual label taken from the first column, first row. The values of the second row are placed at x=1 etc. You could try using the boxes plotting style, which is used with a 'conventional' x-axis and which might support a logscale in x. - Christoph
Here is a data sample : X Y 1 1000 2 300 5 150 20 10 135 3 What you're saying is that by default the histogram x-axis isn't numeric? That would explain why I can't have a logscale. - SOKS

1 Answers

4
votes

Gnuplot histograms work a bit differently from what you might think. The x-axis isn't numeric. In your case the value in the first row, second column is placed at an x-value of 0 with the y-value taken from the second column and a manual label taken from the first column, first row. The values of the second row are placed at x=1 etc.

You can try using the boxes plotting style, which is used with a 'conventional' x-axis and supports a logscale in x:

set logscale xy
set offset 0,0,1,1
set boxwidth 0.9 relative
set style fill solid noborder
plot 'data.dat' with boxes

With the data file data.dat

1 1000
2 300 
5 150 
20 10 
135 3

this gives the result (with 4.6.5):

enter image description here

In order to have a fixed boxwidth and a varying box distance, you can use a third column to specify a box width as percentage of the x-value:

set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5) with boxes

enter image description here

Putting the actual values on the x-axis works as follows:

set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5):xtic(1) with boxes

enter image description here