Gnuplot: plotting results from different sources in one graph - plot

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.

Related

Using gnuplot to plot points with color and x-marks

I have been trying this for a few hours but I am not getting anywhere.
What I am trying to do is this:
I have a solution from a simulation with x and y values and a value for each point.
I am trying to plot the data using gnuplot. I want the values in between my data points to be interpolated using color and the points themself shall be marked with a dot, a "x" or sth. like that similar to this (except for the round border and those labels inside):
I have been trying to get a very basic example going. My data file looks like this:
1 1 0.1
1 2 0.3
1 3 0.6
2 1 0.5
2 2 0.7
2 3 0.9
3 1 0.2
3 2 0.8
3 3 0.7
and my gnuplot input like this:
set terminal postscript eps enhanced color font 'Helvetica,10'
set output './production/image1.eps'
set palette gray
set title "Titel"
#set xrange [1:4]
#set yrange [0:10]
set format y "%.1f"
set format x "%.1f"
set xlabel "x-Achse [Einheit]"
set ylabel "y-Achse [Einheit]" rotate by 90
set view map
set pm3d at b map
set pm3d interpolate 2,2
set dgrid3d 50,50,2
splot "inputDatei.dat" u 1:2:3 linecolor palette
The result looks like this:
There are a few issues with this which i cannot resolve:
there is a label in the rip right "inputDatai.dat" u 1:2:3". I tried splot ... label "" but this didnt solve the issue
the interpolation doesnt seem to work. this is visible with a smaller grid
the data points are not highlighted. I tried using splot ... with points but this would only display points at EVERY grid corner which is obviously way too much. Also the input data might not be "regular" but points can be anywhere.
I am very happy if someone could help me with this.
Greetings,
Finn
To your questions:
use unset key before the plot command or splot ... notitle within the plot command
what "does not work" mean? Please explain.
I guess that's similar to here (Superimposing vectors, dgrid3d and pm3d in gnuplot for 3D plot). You have to switch off interpolating for the highlighted points. I'm not sure whether this can be done within a plot command, so you have to plot the interpolated data into a separate datablock via set table and then switch off interpolation.
Code:
### interpolate data with highlighted datapoints
reset session
$Data <<EOD
1 1 0.1
1 2 0.3
1 3 0.6
2 1 0.5
2 2 0.7
2 3 0.9
2.5 2.5 0.1
3 1 0.2
3 2 0.8
3 3 0.7
EOD
set size square
set view map
set pm3d at b
set pm3d interpolate 2,2
set dgrid3d 50,50,2
set table $DataInterpolated
splot $Data u 1:2:3
unset table
unset dgrid3d
set palette grey
set xrange [0.9:3.1]
set yrange [0.9:3.1]
splot $DataInterpolated u 1:2:3 w pm3d palette notitle, \
$Data u 1:2:3 w p pt 1 lw 2 lc rgb "red" notitle
### end of code
Result:

How to force color range in gnuplot

I'm using Gnuplot 4.6. I have data files each containing 3 columns of data: X coordinate, Y coordinate and temperature. I wish to make an animation of plots of temperature as a function of X and Y coordinates. For this I'm using the following script:
set pm3d map; set palette;
do for [n=0:200] {splot sprintf("Temperature.%04d.dbl", n) binary array=100:100:1 form="%double" title 'file number'.n}
My problem is with the fact that after a few plots, the distribution of colors changes, both in the plot and in the legend. This makes the reading from the graph really hard.
I consulted the following post:
gnuplot heat map color range
and since the range of the temperature variable is from 0.0 to 1.2 I thought to use:
set zrange [0.0:1.2]; set cbrange [0.0:1.2];
but it doesn't help and the temperature color continues to be autoscaled from plot to plot. Any suggestions?
In addition to setting cbrange, you could try defining your own palette by
set palette defined (0 "black",\
0.2 "red",\
0.4 "orange-red",\
0.6 "orange",\
0.8 "yellow",\
1.0 "light-green",\
1.2 "green")
Or if you want discrete values:
set palette defined (0 "black",\
0.2 "black",\
0.2 "red",\
0.4 "red",\
0.4 "orange-red",\
0.6 "orange-red",\
0.6 "orange",\
0.8 "orange",\
0.8 "yellow",\
1.0 "yellow",\
1.0 "light-green",\
1.2 "light-green")

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

Data disappears when logscale is used in gnuplot

I have successfully made a nice looking histogram in gnuplot with a normal scale but when I add
set logscale y
to my code, the data disappears.
I discovered that logscale does not work with the function I am using to make the histogram (shown in the following link).
https://stackoverflow.com/a/2538846/2506689
Does anyone have any suggestions on how to fix this?
set table to the rescue!
Note that I typed all of this into the interactive prompt and copy/pasted my terminal contents. As such, my commands that follow are prefixed by a gnuplot> which you won't include in your script :-)
First, I generate some data using python ...
import numpy as np
np.savetxt('foobar.txt',np.random.random(1000))
That wasn't hard. Now time to set up gnuplot functions/constants:
gnuplot> binwidth = 0.05
gnuplot> bin(x,width)=width*floor(x/width)
gnuplot> plot 'foobar.txt' using (bin($1,binwidth)):(1.0) smooth freq with boxes
Ok, it works with non-logscale data. That's good. Lets write that data into a separate file using set table
gnuplot> set table 'foobar.table'
gnuplot> plot 'foobar.txt' using (bin($1,binwidth)):(1.0) smooth freq with boxes
gnuplot> unset table
Now I look at the data gnuplot wrote out to see what's there.
gnuplot> !head foobar.table
# Curve 0 of 1, 21 points
# Curve title: "'foobar.txt' using (bin($1,binwidth)):(1.0)"
# x y xlow xhigh type
0 40 0 0 i
0.05 57 0.05 0.05 i
0.1 52 0.1 0.1 i
0.15 56 0.15 0.15 i
0.2 49 0.2 0.2 i
0.25 55 0.25 0.25 i
Unfortunately, it looks like xlow and xhigh are always the same (possible bug?). But that's Ok, we're using a constant binwidth anyway. We'll just use that as the width.
gnuplot> set logscale y
gnuplot> plot 'foobar.table' u 1:2:(binwidth) w boxes
I should note that I've been a little loose with my box positions. To really get it right, you probably need to shift the center of the boxes to the right by half a binwidth:
gnuplot> plot 'foobar.table' u ($1+0.5*binwidth):2:(binwidth) w boxes

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