Plot received powers with gnuplot - gnuplot

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:

Related

Getting gnuplot to put bars side-by-side

I have the following gnuplot script:
set autoscale
unset log
unset label
unset term
unset output
set xtics rotate by -90
set ytic auto
unset title
set xlabel "Survey metadata attribute subset"
set ylabel "Accuracy of classifier (%)"
set boxwidth 0.1
set style fill solid
set term eps
set output "metadata.eps"
plot "metadata.dat" using 1:3:xtic(2) title "PART" with boxes, \
"metadata.dat" using 1:5:xtic(2) title "JRip" with boxes, \
"metadata.dat" using 1:7:xtic(2) title "FURIA" with boxes
However, this draws all 3 sets of bars on top of each other, while I want them side by side, in that order, grouped together. So it should go something like: PARTbar, JRipbar, FURIAbar, gap, PARTbar, JRipbar, FURIAbar, gap, etc. How would I go about doing this?
I guess what you want is set style histogram clustered.
I have taken a minimal dataset (see bottom) graphing it with
set style histogram clustered
set xtics rotate by -90
unset title
set xlabel "Survey metadata attribute subset"
set ylabel "Accuracy of classifier (%)"
set boxwidth 1
set style fill solid
set term png
set output "so.png"
plot [-0.5:2.75][1:17] "so.dat"using 3:xtic(2) title "PART" with histograms, \
"" using 4 title "JRip" with histograms, \
"" using 5 title "FURIA" with histograms
which yields
I think you can take it further from here.
Data file "so.dat":
1 a 10 12 15
2 b 12 14 16
3 c 11 15 14
Suppose your data looks like this
1 a 2 3 4
2 b 1 4 5
3 c 6 7 8
One option is to set the boxwidth smaller and manually adjust the box positions so that they line up.
We can do that with
set boxwidth 0.25
plot datafile using ($1-0.25):3 with boxes t "First Series", \
"" using 1:4:xtic(2) with boxes t "Second Series", \
"" using ($1+0.25):5 with boxes t "Third Series"
This results in the following graph
Notice that I only set the xtics on the second series (the one in the middle), and I subtracted the boxwidth from the first series x coordinate (moving it back by one box unit), and added this to the last series (moving it forward by one box unit). I choose to use a boxwidth of 0.25 instead of 0.33 to allow a little gap between groups. Putting the xtic only on the second series ensures that it is on the one in the middle. With more boxes you will use a different width and will have to determine on which one to set the xtic labels.
An alternative is to use the histogram style. With the default boxwidth of 1, you can do
plot datafile u 3 with histogram t "First Series", \
"" u 4:xtic(2) with histogram t "Second Series", \
"" u 5 with histogram t "Third Series"
In this case, it doesn't matter where you place the xtic specification.
The histogram styles are very complex having lots of options. Essentially it consists of multiple plotting styles that are all invoked with the with histogram specification.
Which one of these methods to choose is mostly a matter of personal preference. The first is how you'd do this before the histogram style was added. The box method gives you more manual control over the final result, but the histogram style automates a lot of the details of getting those boxes just right.

Gnuplot stacked histogram skipping the first bin

I'm trying to use gnuplot to plot a stacked histogram of some data but it skips the first bin (the first row of the data file).
The data is:
1 0.2512 0.0103 0.9679
2 0.4730 0.2432 0.8468
3 0.6669 0.2826 0.6895
4 0.6304 0.2268 0.7424
And the plot code is
set title "Data"
set key invert reverse Left outside
set key autotitle columnheader
set style data histogram
set style histogram rowstacked
set style fill solid border -1
#set boxwidth 0.75
plot 'data.dat' using 2:xtic(1) title 'X', '' using 3 title 'Y', '' using 4 title 'Z'
The output is. I checked it and it correctly displays the data of the 2nd, 3rd and 4th rows of the data file. Why am I missing the first bin..?
Thanks a lot!
I already checked this with no help: Using gnuplot for stacked histograms
As it turns out, it was a very simple mistake, that I've fixed mostly thanks to Azad comment about the titles.
The new code is:
set title "Position error along the three axis"
set key invert reverse Left outside
#set key autotitle columnheader
set style data histogram
set style histogram rowstacked
set style fill solid border -1
#set boxwidth 0.75
plot 'data.dat' using 2:xtic(1), '' using 3, '' using 4
Titles have been removed from the code. Gnuplot was taking the first row (which should have been the first bin) as the titles and then it was overwritten by the title 'X' etc.
The new data looks like this:
0 X Y Z
1 0.2512 0.0103 0.9679
2 0.4730 0.2432 0.8468
3 0.6669 0.2826 0.6895
4 0.6304 0.2268 0.7424
This fixed the problem, now all the bins are correctly displayed!

increasing yRange from negetive to positive in gnuplot

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)

Gnuplot histogram x logscale

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

Plotting data vertically with gnuplot

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

Resources