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)
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):
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
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
Related
I am trying a very easy gnuplot graph.
Data is
Average 0.177 0.167
Median 0.179 0.173
and graph code:
set style fill solid border 0
set boxwidth 1.5
set style histogram clustered
set style data histograms
plot "PDR.txt" using 2:xtic(1) lt rgb "#406090",\"" 0" using 3 lt rgb "#40FF0
problem is that the graph produced has way too much space everywhere, in the middle, but especially left and right. How can I reduce those?
You should set the xrange to the desired length, e.g. set xrange [-0.25:1.5] looks alright on my computer
I have a gnuplot script which plots a histogram. I used the following syntax:
set style data histogram
set style histogram cluster gap 2
set style fill solid
set logscale y
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
plot 'histogram_data' using (column(0)):2:(0.5):(rgb($3,$4,$5)):xticlabels(1) w boxes notitle lc rgb variable
What the last line does is: using column 1 as x labels, column 2 as the height of the histogram bars, 0.5 as box width, and columns 3, 4 and 5 as the rgb values to colour the bars.
Now, the problem is that modifying the gap parameter in line 2 does not change in any way the spacing between bars, even though as far as I understand that is the correct way to adjust such spacing. I am using gnuplot 4.6 patchlevel 4.
I found a way to do this with boxes, though I do not consider it very clean:
plot 'histogram_data' u (column(0)*2+1):2 w boxes notitle lc rgb 'white',\
'histogram_data' u (column(0)*2):2:(rgb($3,$4,$5)):xticlabels(1) w boxes notitle lc rgb variable;
This command is plotting all the data of the main plot on even slots and a white box on odd slots. So the first line in the plot command is plotting the gaps between every box of the plot (the width of these gaps can be specified using the boxwidth property I think but I haven't tested this), while the second line is drawing the actual plot.
I could not find a way to do this with the histogram plotting style, keeping the variable colours specified in the data file.
I want my yrange to be between -100 and 0, and here is my plot in gnuplot
I want the y axis to be from -100 increasing up to 0!
what should I do?!
BTW:
My plot is histogram!
when I set it to [-100:0] my plot is upside down, the bars are from up to down!!
set style data histogram
set yrange [-100:0]
set style fill solid 0.3
set bars front
plot 'mean.rssi' using 2:xticlabels(1) title columnheader
above is my code, histogram is plotted from 0 to -100, but I want to be from -100 to 0!
The file mean.rssi contains two columns, for example
Dlink -93
That isn't directly supported, histograms always have their base line at 0, positive values give boxes oriented upwards, negative values downwards.
Since your range is known, you should convert the range [-100:0] to the range [0:100] and relabel the y-axis:
set style data histogram
set yrange [0:100]
set ytics ('-100' 0)
set for [i=-100:0:20] ytics add (sprintf('%d', i) i + 100)
plot 'mean.rssi' using ($2 + 100):xticlabels(1)
Other solutions would use the boxes plotting style. If you could use this depends on whether you need the stacking features of the histogram style.
You can specify ranges with square brackes. For example, to specify both X and Y ranges you could do:
plot [-20:20][-50:50] sin(x)
which would set the X-range to [-20,20] and the Y-range to [-50,50].
To only set the Y-range, you can set the X-range to the empty brackets [], e.g.
plot [][-50:50] sin(x)
To only set the X-range you can do something similar, or just omit the Y-range completely:
plot [-20:20] sin(x)
I have a data file with a single column of data. By default, gnuplot renders this on the x-axis from left to right. However, I want to plot this data vertically from top to bottom. How can I do this?
The relevant excerpt from my plot file:
set size 1.0, 1.0
set terminal postscript eps enhanced color dashed lw 1 "Helvetica" 14
set output "ocean-diffuse.eps"
set autoscale
set xtic auto
set ytic auto
plot '0000086400.dat' using 1 with line, \
'0000172800.dat' using 1 with line
In order to have the single column used as x-value, use:
plot '0000086400.dat' using 1:0
That uses the row number (column 0) as y-values. Of course you can do any scaling and computation with the row number as
f(x) = x
plot '0000086400.dat' using 1:(f($0))
To have the y-axis reversed, use
set yrange [*:*] reverse
I'd like to plot the received powers over different wireless channels. For each channel, I have three values, and I want to plot them stacked.
Actually, this is my script:
set boxwidth 0.6 relative
set ylabel "dBm"
set xlabel "Channel"
set style fill solid
set key off
plot "RR1" using 1:2 with boxes, "RR2" using 1:2 with boxes, "RR3" using 1:2 with boxes
The problem is that since they are negative values (dBm), it plots from 0 to the value it finds, and thus the highest power is on the top. I'd like to plot a somewhat reverse image, with the blue box starting from the bottom up to the value it reaches, and the same for the other two values.
Any idea?
My data looks like this
21.0 -93.9207
22.0 -92.241
23.0 -93.452
One possibity is to use the boxxyerrorbars plotting style:
reset
set ylabel "dBm"
set xlabel "Channel"
set style fill solid
set key off
set style data boxxyerrorbars
set xtics 1
set autoscale xfix
set offset 0.5,0.5,0,0
ylow = -100
plot for [i=3:1:-1] sprintf("RR%d", i) using 1:(0.5*($2+ylow)):(0.3):(0.5*($2-ylow)) lt i
Here, I used a fixed lower y-value, but you could also extract it from the data file with stats and do some other tweaking.
In the using statement, the second column gives the box center, which is the mean of actual y-value and the lower boundary, the third column is x-delta (half of the actual box width), and the fourth column is y-delta.
With some more data values, this gives: