Two Boxplots for one X position using gnuplot - graph

I have 2 sets of data A and B, each with a y value for x=100, 200, 300. I want to create one graph which shows the difference between these two data sets. As such this means that for each x, there will be two boxplots(one for data A and one for data B).
for example, this is how the columns are organized in my data.
DataSet A
# x=100 200 300
1 2 3
1.1 2.1 3.1
1.2 2.2 3.2
1 2 3
1.01 2.01 3.01
DataSet B
# x=100 200 300
6 7 9
6.1 7.1 9.1
6.2 7.2 9.2
6 7 9
6.01 7.01 9.01
I was able to get two graphs out of this data using:
set style fill solid 0.25 border -1
set style boxplot outliers pointtype 7
set style data boxplot
set xtics ('100' 1, '200' 2, '300' 3)
plot for [i=1:3] "A.txt" using (i):i notitle
plot for [i=1:3] "B.txt" using (i):i notitle
However, I am facing issues when combining it into one.
Please help.

If you want to have them stacked above each other (in case they don't overlap), then you can just combine the two plot into one with
plot for [i=1:3] "A.txt" using (i):i notitle,\
for [i=1:3] "B.txt" using (i):i notitle
If they can overlap, you may want to put them side-by-side with
set boxwidth 0.3
plot for [i=1:3] "A.txt" using (i-0.15):i notitle,\
for [i=1:3] "B.txt" using (i+0.15):i notitle
Just to give two example of how you could combine those plots.

Related

Gnuplot: plotting results from different sources in one graph

I am trying to compare the results of a measurement from different collaborations using gnuplot. The plot should ideally look like this:
I can't figure out how to plot the different results one on top of the other, with the labels on the right. I would be really grateful if anyone could help me.
I show two approaches, depending of your data file. Two possible structures are data01.dat
# data01.dat
alpha error
1.0 0.2
2.0 0.2
1.5 0.2
or data02.dat
# data02.dat
Collab alpha error
1 1.0 0.2
2 2.0 0.2
3 1.5 0.2
Using the data01-structure:
reset
set encoding utf8
set terminal wxt size 480,600 font "Times New Roman,10"
set tics out nomirror
set xlabel "{/:Italic=12 α}"
set link y2
unset ytics
set y2range [:] reverse
set y2tics 1
set format y2 "Collaboration %g"
set offsets graph 0.1, 0.1, 0.5, 0.5
plot "data01.dat" u 1:0:2 w xerrorbars pt 7 not
Using the data02-structure almost all is the same, except the plot command.
plot "data02.dat" u 2:1:3 w xerrorbars pt 7 not
The results.
I hope be useful.

Gnuplot Multiple files in one Plot

I use gnuplot for plotting data from 4 files on a single graph (png).
I get the 4 plots as different colored lines.
I want them to be of different line types so that the plot can be easily recognized in a black and white print out.
How to do that ? Many thanks for your help.
So what I want is http://gnuplot.sourceforge.net/demo/lines_arrows.html : Second figure. In Gnuplot, I get the plots as different colored lines.
Not entirely sure which detail of your question is the aspect you're struggeling with. When plotting from multiple files you specify this with plot 'FILENAME' using COLUMNS ... , 'FILENAME2' using COLUMNS ...
From the example you posted I see that the lines are black as long as lt -1 stays in. If you take it out, things become colorful. linespoints essentially connects the dots with lines, in the example that's pulled up to set style func linespoints which won't work here, as it's not a function which gets plotted.
Following the example you linked I suggest this:
set title ""
set xlabel ""
set bmargin 6
set offset .05, .05
set xrange [-0.5:3.3]
plot 'd1' using 1:2 lt -1 pt 6 ps 2 title 'pt 6' with linespoints,\
'd2' using 1:2 lt -1 pt 5 ps 2 title 'pt 5' with linespoints,\
'd3' using 1:2 lt -1 pt 7 ps 2 title 'pt 7' with linespoints,\
'd4' using 1:2 lt -1 pt 4 ps 2 title 'pt 4' with linespoints
where d1 looks like:
-0.5 0.8775825619
-0.4 0.921060994
-0.3 0.9553364891
-0.2 0.9800665778
-0.1 0.9950041653
0.0 1.0000000000
0.1 0.9950041653
0.2 0.9800665778
0.3 0.9553364891
0.4 0.921060994
0.5 0.8775825619
0.6 0.8253356149
0.7 0.7648421873
0.8 0.6967067093
0.9 0.6216099683
1.0 0.5403023059
1.1 0.4535961214
1.2 0.3623577545
1.3 0.2674988286
1.4 0.1699671429
1.5 0.0707372017
1.6 -0.0291995223
1.7 -0.1288444943
1.8 -0.2272020947
1.9 -0.3232895669
2.0 -0.4161468365
2.1 -0.5048461046
2.2 -0.5885011173
2.3 -0.6662760213
2.4 -0.7373937155
2.5 -0.8011436155
2.6 -0.8568887534
2.7 -0.904072142
2.8 -0.9422223407
2.9 -0.9709581651
3.0 -0.9899924966
3.1 -0.9991351503
3.2 -0.9982947758
3.3 -0.9874797699
EDIT:
thanks for clarifying. A few more pointers
Colors themselves: I recommend http://colorbrewer2.org/ to pick colors which are "photocopy safe". These tend to be well distinguishable even if printed in grayscale.
Markers: with the point type e.g. pt 5 you can specify different markers for the data. I changed the size with ps 2 in the above example. Especially open and filled markers are easily distinguishable from each other.
Linestyle: you need version 5 of gnuplot:
New features in version 5
* The dot-dash pattern of a line can now be specified independent of other
line properties. See dashtype
(p. 37), set dashtype (p. 115), set linetype (p. 135).
Without upgrading I couldn't get this to run, which is derived from the page you linked:
set termoption dash
unset colorbox
set title ""
set xlabel ""
set bmargin 6
set offset .05, .05
set xrange [-0.5:3.3]
show style line
plot 'd2' using 1:2 with linespoints dt 2 lw 3 lc rgb "black" ps -1,\
'd3' using 1:2 with linespoints dt 1 lc rgb "black" ps -1,\
'd4' using 1:2 with linespoints dt 3 lc rgb "black" ps -1
here dt is short for dash type, lw is line width, lc is line color which i set to black, ps is point style, disabled, so we don't see the points but only lines

take the last data column with AWK to create a linepoints gnuplot

I am working on gnuplot linepoints to create a comulative and normal distribution graph. I have created a file to provide the information to both graphs.
I got a problem when I was trying to plot the last data.
Here is the my script to create the second graph.
plot.plt
set term pos eps
set style data linespoints
set style line 1 lc 8 lt -1
set size 1,1
set yr [0:20]
set key below
set grid
set output 'output.eps'
plot "<awk '{i=i+$3; print $1,i}' data.dat" smooth cumulative t 'twitter' ls 1
data.dat
5.0 1 0.10
9.0 5 0.20
13.0 7 0.30
14.0 1 0.20
15.0 9 0.20
I want to create x axis with the first column and y axis with the last column. so the y axis range must between 0 to 1. which part should I change? thanks
Using smooth cumulative is enough, no need for awk. You are doing the same operation twice, once with gnuplot and once with awk. Simply do
plot 'data.dat' using 1:3 smooth cumulative

Gnuplot: plotting only specific values of the dataset using lines or linespoints

Let's suppose my dataset is like this:
0 0.3
1 0.12
2 0.4
3 0.6
4 0.9
...
10 0.23
11 0.6
...
20 0.34
21 0.4
...
and I'd like to plot values of both columns only if $1 % 10 == 0, i.e., (0,0.3), (10,0.23), (20,0.34) and so on... Now, I've written the following conditional script:
plot "data.csv" using 1:(int($1)%10==0?$2:0/0) title 'r=1' with linespoints linewidth 3 linecolor rgb 'blue'
The problem is that lines are not shown, but only points.
This is because, for all rows where the condition is not satisfied, the corresponding value is undefined. Anyway, what I need is quite different; I want those specific values to be just ignored, not to set to undefined. Is there a way to do that just using gnuplot (not awk and so on)?
In case you have all intermediate steps, i.e., full data for number (which is suspect based on your axis labelled iterations), you best use the every option
plot "data.csv" every 10 with linespoints
Otherwise, I would use awk inside your script for simplicity
plot "<awk '$1%10==0' data8" with linespoints
The probably with your original script, is that the points are shown, but with value infinity. It is a feature that these lines are not shown.

Gnuplot---clustered rowstacked bars

How can I make clustered rowstacked bars in gnuplot? It know how to get a clustered bars, but
not a cluster of rowstacked bars. Thanks!
Edit: in a cluster, stacked bars should use different colors/patterns as well.
I'm not completely sure how to go about doing this, but, one idea is to make it so that the boxes are touching each other
`set boxwidth 1`
That doesn't quite get you a "clustered" look yet -- To get a clustered look, I think you'd need to insert a row (maybe column) of zeros...(I haven't sorted through that one in my head yet) into your datafile where you want a cluster break.
Of course, you wouldn't need to set the boxwidth either I suppose...clustered just depends on the breaking every once in a while...
If I understand the original post right, it should be easy to accomplish with gnuplot if you can preprocess your data to offset x coordinates of specific data series.
To illustrate the approach I will use the following data in 3 data series:
# impulse.dat
0.9 1
1.9 4
2.9 3
3.9 5
1.0 1
2.0 2
3.0 4
4.0 2
1.1 3
2.1 3
3.1 5
4.1 4
Here each series has x-coordinates shifted by .1. To plot it I choose impulses of width 10.
plot [0:5] [0:6] 'impulse.dat' ind 0 w imp lw 10, \
'impulse.dat' ind 1 w imp lw 10, \
'impulse.dat' ind 2 w imp lw 10
Edit: to combine this with Matt's suggestion to use boxes would definitely be better:
set boxwidth 0.1
set fill solid
plot [0:5] [0:6] 'impulse.dat' ind 0 w boxes,\
'impulse.dat' ind 1 w boxes, \
'impulse.dat' ind 2 w boxes
Following is the picture with impulses.

Resources