So, im trying to plot two diferent box plot with diferent files, here my code:
set boxwidth 0.5
set style fill solid 0.5
set xlabel ""
set ylabel "Boxplot Value"
set grid layerdefault
set xtics ("Data A" 1, "Data B" 2)
set xtics rotate by -50
plot "out4.txt" using (1):1 notitle with boxplot, "out20.txt" using (1):2 notitle with boxplot
And this error shows up: "boxplot.gnu", line 8: warning: Skipping data file with no valid points
My data is arranged like this:
2
3
4
5
6
7
6
23
423
42
342
34
234
Just one column, its the same data in both files.
If your file "out20.txt" also consists of only one column, what should gnuplot plot if you write "out20.txt" using (1):2? There is no second column to plot. That's what gnuplot is telling you "Skipping data file with no valid points".
If "out4.txt" corresponds to Data A at x=1 and "out20.txt" to Data B at x=2, then changing line 8 to the following should show your graph:
plot "out4.txt" using (1):1 notitle with boxplot, "out20.txt" using (2):1 notitle with boxplot
Related
I want to create a simple histogram in gnuplot and want to adapt the color of the bars according to the data. Currently, I am struggling with the mapping between color and data.
Let's say I have the following data file:
X, 500.00, 100.00, 1
Y, 600.00, 200.00, 2
I generate the histogram with the following code:
reset
fontsize = 12
set terminal png
set output "file.png"
set style fill solid 1.00 border 0
set style histogram errorbars gap 2 lw 1
set style data histogram
set xtics rotate by -45
set grid ytics
set xlabel "label"
set ylabel "label"
set yrange [0:*]
set datafile separator ","
plot 'data.dat' using 2:3:4:xtic(1) ti "" lc variable
Now I want to create a mapping between the fourth column in the data and the color, e.g. 1 -> yellow, 2 -> blue.
I assumed that I can define something like the following
set style line 1 linecolor rgb "yellow"
set style line 2 linecolor rgb "blue"
but this code is not working since it defines styles and not colors. On the other hand I have read in the documentation that "rgb variable" is only available in 3D plotting mode (splot), so I think in this terms my whole approach might go in a wrong direction.
Does anyone know how to realise the mapping between data and line colors?
Have you tried with the command palette? I had the same problems some times ago. I wanted to make this plot (that is in some ways what you need)
So I used the number of elements in a column of the histogram to set the color of that column. My datafile looked like
#MY_FILE
...
26 0.02302 2302
28 0.02233 2233
30 0.02261 2261
32 0.02383 2383
34 0.02279 2279
36 0.02366 2366
38 0.02226 2226
40 0.02148 2148
...
#EOF
where the first row $1 was the n parameter, the second one $2 was my pdf (simply the histogram normalized) and the third $3 column was the number of occurrence int the bin. Then I used the last column as the parameter to color my graph with the command
set palette model RGB defined (1 "blue", 2 "red")
that create a gradient between the starting point 1 and the end 2. Then to use the palette i plotted with the line
p 'MY_FILE' u 1:2:3 w boxes palette
where the w boxes was the command to generate my histogram, and the palette (also pal) command was the command o set the color, which use the third column as specified in u 1:2:3, where the 1:2 is my histogram and 3 is the color gradient.
if you don't want the lateral strip of color (heatmap) just type in gnuplot
unset colorbox
Here's some documentation about palette command in gnuplot:
http://gnuplot.sourceforge.net/demo_5.0/pm3dcolors.html
type help palette on gnuplot
THIS could be particularly HELPFUL: http://www.gnuplotting.org/defining-a-palette-with-discrete-colors/
If I set a specific yrange and plot in a pdf terminal with this plot command:
plot "data.dat" u 1:4:5:6 w yerrorbars pt 6 ps 0.5 t "R_t"
errorbars that belong to data points outside the yrange, but end inside the yrange are not shown.
How do I force gnuplot to draw those. I already tried "set clip one/two"
The only workaround I found is to plot the data 3 times, once for the central point and once for each side of the error bar.
Use "-" as symbol for the errorbars and use their own "errorbars" to draw a line to the central point.
You could use multiplot to achieve this.
Set your plot to have zero margins, so the axes are on the border of the canvas, and switch of all tics and borders for the first plot.
Switch on the axes, tics etc. again, and do an empty plot that you set at the correct position using set size and set origin. You'll have to do some math to calculate the exact position.
#MaVo159, you can reduce it to plotting only twice by using with yerrorbars and with vectors (check help vectors). You need to set the proper arrow style, check help arrowstyle.
However, this works only for gnuplot>=5.2.3, for earlier versions there seems to be a bug which plots the arrowhead at the wrong side for some of the vectors extending the graph.
You nevertheless have to plot once with yerrorbars in order to get the proper legend.
Script: (works for gnuplot>=5.2.3, May 2018)
### plot errorbars from points outside the range
reset
$Data <<EOD
1 9 5.11 8.32
2 8 6.20 9.22
3 6 5.31 6.31
4 5 4.41 5.51
5 4 3.31 4.71
6 2.9 2.81 3.71
7 2 1.11 3.41
EOD
set yrange[3:7]
set offsets 1,1,0,0
set style arrow 1 heads size 0.05,90 lw 2 lc 1
set multiplot layout 2,1
plot $Data u 1:2:3:4 w yerrorbars pt 6 ps 2 lw 2
plot $Data u 1:2:3:4 w yerrorbars pt 6 ps 2 lw 2, \
'' u 1:3:(0):($4-$3) w vec as 1 notitle
unset multiplot
### end of script
Result:
You could modify your data file: Because the central value of the data point is outside the plot range you could set it equal to the errorbar's end point that would be still visible in your plot.
Example:
plot range: set yrange[-2:2]
data point: 1, -3, -1, -4 (x, y, ylow, yhigh)
set data point to: 1, -1, -1, -4
Attention: Since you have to edit your data file you should
Make a copy of the original data file
Be very careful when editing the file
Keep in mind, that when changing the plot range such that the central
value of the data point becomes visible you have to use the original data point. Otherwise you will see the correct error bar but there will be no central value plotted. (this is equivalent to setting 'point type' to 0)
I'm having this script to plot some data in Gnuplot. Unfortunately, my plot doesn't print the lines, only the dots.
What have I done wrong?
#!/usr/bin/gnuplot
reset
set terminal png
set output 'picture.png'
set xlabel "n"
set ylabel "time (s)"
set yrange [0:2]
set title "title"
set key reverse Left outside
set grid
set style data linespoints
plot "bla.txt" using 1:2 title "bla" with linespoints ls 1
Most probably, your data file contains empty lines between successive data entries.
A data file with
1 2
2 4
5 6
shows only three points when plotted with
plot 'data.txt' using 1:2 with linespoints
whereas a data file
1 2
3 4
5 6
also shows connecting lines.
That is simply how gnuplot handles its data files.
My data file Im using for plotting:
0.005200 1
0.005333 2
0.005333 3
0.005333 4
0.005333 5
0.005467 6
0.005467 7
0.005467 8
My GNUplot script used for plotting:
#!/usr/bin/gnuplot
set xlabel "test"
set ylabel "value"
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
set autoscale
set terminal postscript portrait enhanced color dashed lw 1 'Helvetica' 14
set style line 2 lc rgb 'red' pt 7 # circle
set output 'test.eps'
plot 'data.txt' using 2:1 with points ls 2 title "time series plot"
Output image generated with GNUplot:
As you see in the data file I posted, value for the second, third, fourth and the fifth test is 0.005333. (As well as for the sixth, seventh and eighth test - there is a value of 0.005467).
But you can't see that on a figure - take a look at it. For the second, third, fourth and the fifth test the value on the figure is in somewhere between the 0.0053 and 0.00535 and I need the dots to be in the EXACT position on figure as its on the text file.
I have so much such files, is there any "portable" way to use it for every file I have?
The points are of course in the correct position. Add
set ytics add (0.005333, 0.005467)
to your script to see this:
My data file looks like this
A 20120301 4
A 20120302 3
B 20120301 5
B 20120302 6
C 20120303 5
except there are many more than just A,B,C and I want to create a stacked graph with gnuplot (similar to the "Stacked histograms" from the gnuplot demos)
20120301 = (A:4 + B:5)
20120302 = (A:3 + B:6)
20120303 = (C:5)
So far I could not convince plot to read the data in that format. Do I have re-arrange the data file for this? Or is there a way for gnuplot to read the data in that format?
I think I've managed to beat it into a form that will work (you'll need at least gnuplot 4.3):
set boxwidth 0.75 absolute
set style fill solid 1.00 border lt -1
set datafile missing '-'
set style histogram rowstacked
set style data histograms
set yrange [0:]
plot for [i=2:4] 'test.dat' u i,'' u (0.0):xtic(1) notitle
and here's the datafile test.dat
#date A B C
#missing data is marked by a minus sign
20120301 4 5 -
20120302 3 6 -
20120303 - - 5
Phew! I've never been much good with gnuplot when it comes to histograms. Hopefully this will work for you (Sorry about the change to your datafile).