There is a style to fill the space between two functions of x.
Examples of such plots can be found e.g. at http://gnuplot.sourceforge.net/demo/fillbetween.html
Is there any way to make similar plot, but with flipped x and y axes?
Here is the desired shape of a curve (without rotated/mirrored labels, titles and legends, of course)...
It could be done with closed contour (like last example here http://www.gnuplot.info/demo_svg_cvs/fillcrvs.html), but this would require reshuffling the data file. Any other options?
Thank you!
You can't do this directly. From help filledcurves:
The third variant fills the area between two curves sampled at the same set of
x coordinates. It requires three columns of input data (x, y1, y2).
I don't think you can specify (y, x1, x2) directly. As a workaround you can the area between the y axis and the larger function in some color, and then fill the area between the y axis and the smaller function in white:
x1(y) = cos(y)+1
x2(y) = cos(y)+2
xmax(y) = (x1(y) > x2(y) ? x1(y) : x2(y))
xmin(y) = (x1(y) < x2(y) ? x1(y) : x2(y))
plot '+' using (xmax($1)):1 with filledcurve y1, \
'+' using (xmin($1)):1 with filledcurve y1 fillcolor rgb "white"
This probably has to be tweaked a little if one or both of the two functions can be negative.
With gnuplot >=5.2 it could be tweaked even further because it allows arrays.
The following code shows a workaround how filled curves between vertically oriented curves can be realized. You can even use transparency. If you download the attached PNG you will notice that it actually has a transparent background. The basic idea behind this workaround is to make closed areas and fill them. For this, you need to reverse one border, concatenate the borders and plot them filled. Unfortunately, gnuplot has no function to reverse datapoints in a column, so you have to do it in a special procedure yourself.
The code:
### "Vertical" filledcurves
reset session
# create some dummy data
N = 50
set samples N
set xrange [-5:5]
set table $Data
plot '+' u (sin($1)):1:(rand(0)*0.3+1) with table
unset table
# put Borders into arrays
stats $Data nooutput
RowCount = STATS_records
array BorderX1[RowCount]
array BorderX2[RowCount]
array BorderY[RowCount]
set table $Dummy
plot $Data u (BorderX1[$0+1]=$1-$3):(BorderX2[$0+1]=$1+$3):(BorderY[$0+1]=$2) with table
unset table
# reverse BorderX2 and merge borders
set samples RowCount
set table $Border
plot '+' u (BorderX1[$0+1]):(BorderY[$0+1]) with table
plot '+' u (BorderX2[RowCount-$0]):(BorderY[RowCount-$0]) with table
unset table
# make the plot
set object 1 rect at 0,-3 size 10,0.5 fs solid 1.0 fc rgb "black" back
set yrange[-5:5]
plot \
$Border u 1:2 w filledcurves fc rgb "#AA00FF00" not,\
$Border u ($1*1.5):2 w filledcurves fc rgb "#AAFFFF00" not,\
$Data u ($1+2.5):2 w filledcurves y2 fc rgb "brown" not,\
$Data u 1:2 w l lw 8 lc rgb "blue" not,\
'+' u 1:(cos($1)-0.5):(cos($1)+0.5) w filledcurves lc rgb "grey" not,\
'+' u 1:(cos($1)):(1) w l lw 3 dt 2 lc rgb "white" not
### end of code
The result:
Update: These are two alternative and simpler approaches compared to my first answer. One of them works even with gnuplot 5.0.
The plotting style filledcurves (so far) can only fill between two y-curves with identical x-values. However, gnuplot can fill closed curves. So, make the curve closed. Like in my first answer, you can do this if you reverse one curve and add it to the other one.
The assumption for both scripts is that the data has a common y-column, i.e. is organized in 3 columns, e.g. here: y x1 x2
Data: SO50676753.dat (same as OP's data, from silver.dat in the gnuplot demo directory)
# y x1 x2
10 280 16.7332
20 191 13.8203
30 152 12.3288
40 150 12.2474
50 104 10.1980
60 77 8.7750
70 69 8.3066
80 60 7.7460
90 60 7.7460
100 51 7.1414
110 41 6.4031
120 34 5.8310
130 35 5.9161
140 34 5.8310
150 24 4.8990
160 24 4.8990
170 19 4.3589
180 21 4.5826
190 20 4.4721
200 18 4.2426
210 21 4.5826
220 15 3.8730
230 19 4.3589
240 12 3.4641
250 20 4.4721
260 20 4.4721
270 18 4.2426
280 18 4.2426
290 20 4.4721
300 12 3.4641
310 26 5.0990
320 17 4.1231
330 8 2.8284
340 6 2.4495
350 8 2.8284
360 10 3.1623
370 20 4.4721
380 14 3.7417
390 8 2.8284
400 10 3.1623
410 9 3.0000
420 8 2.8284
430 10 3.1623
440 13 3.6056
450 9 3.0000
460 5 2.2361
470 7 2.6458
480 11 3.3166
500 7 2.6458
510 9 3.0000
520 12 3.4641
530 4 2.0000
540 7 2.6458
550 10 3.1623
560 9 3.0000
580 8 2.8284
590 9 3.0000
600 5 2.2361
Script 1: (works with gnuplot>=5.0.0)
Here you assume that you have monotonic and unique y-values. With this you can use the option smooth unique (available at least in gnuplot 4.x versions) to reverse one curve. However, since this solution here uses datablocks and plotting style with table it requires at least gnuplot 5.0.0. Maybe with some workarounds and temporary files you can also get it to work with some 4.6 versions.
### fill between vertical curves
reset session
FILE = "SO50676753.dat"
set table $Temp
plot FILE u 1:2
plot FILE u (-$1):3 smooth unique
set table $Data
plot $Temp u 2:1 index 0 w table, \
'' u 2:(-$1) index 1 w table
unset table
set style fill solid 0.3
set grid x,y
plot $Data u 1:2 w filledcurves
### end of script
Script 2: (works with gnuplot>=5.2.0)
With this solution there are no special assumptions about the data, but since it uses indexing of datablocks it requires gnuplot>=5.2.0.
### fill between vertical curves
reset session
FILE = "SO50676753.dat"
set table $Temp1
plot FILE u 2:1 w table
set table $Temp2
plot FILE u 3:1 w table
unset table
set print $Data
do for [i=1:|$Temp1|] { print $Temp1[i] }
do for [i=|$Temp2|:1:-1] { print $Temp2[i] } # reverse data
set print
set style fill solid 0.3
set grid x,y
plot $Data u 1:2 w filledcurves
### end of script
Result: (same for both scripts):
Hi Im using this data to get a 3d/2d like histogram.
I want to label each histogram column with a 'dx cx' label preferable on top of the column.
With my example the graph is drawing correctly, but there are no labels. if I'm using only the using 1:2:3:4 with labels offset 1 part, it shows the label with no lines. And it only shows the label to the space character, can I somehow escape the space?
Could anyone help please?
reset
unset key
set xrange [0:262.5]
set yrange [0:350]
set zrange [0:5]
set xtics 50
set ytics 50 offset .6,-.3
set ztics 1,1
set grid x y z back
set xyplane 0
set terminal pdf
set output "test.pdf"
splot '-' using 1:2:3 with lines, '' using 1:2:3:4 with labels offset 1
27.8409 350 0
27.8409 350 0.419595 d0 c3
31.8182 350 0.419595
31.8182 350 0
31.8182 350 0
31.8182 350 0.61032 d0 c4
35.7955 350 0.61032
35.7955 350 0
35.7955 350 0
35.7955 350 0.740013 d0 c5
39.7727 350 0.740013
39.7727 350 0
39.7727 350 0
39.7727 350 0.747642 d0 c6
43.75 350 0.747642
43.75 350 0
43.75 350 0
43.75 350 0.633207 d1 c1
47.7273 350 0.633207
47.7273 350 0
47.7273 350 0
47.7273 350 0.442482 d1 c2
51.7045 350 0.442482
51.7045 350 0
e
Your second plot is never done. The inline data is gone after the first part. You have to feed it twice (same dataset again after the "e") or in gp5 you can use a new form of inline data:
$data << EOD
1 2 3
2 3 4
3 4 5
EOD
splot $data, $data using 1:2:($2**2)
If the data comes in via stdin ("-"), you can use set table to plot it to a temporary file or to an inline data set set table $dat; plot "-"; unset table.
How set point type from data in gnuplot?
gnuplot script:
set terminal pngcairo size 640,480
set output "points.png"
set style data points
set auto x
set autoscale x
unset colorbox
plot 'test.data' using 2:1 with points notitle
test.data
32 35 8
34 34 6
36 28 1
34 32 2
28 30 7
38 30 9
34 29 2
35 36 9
39 34 3
31 33 9
28 31 6
35 30 5
33 41 4
32 37 3
how get point type from 3 column?
plot 'gnuplot.data' using 2:1 with points pt (:3) notitle // error
abstraction example:
need:
gnuplot Version 4.6 patchlevel 4
There is no option to select the point type from the data file based on a column (equivalent to linecolor variable, pointsize variable or arrowstyle variable). Basically you have two options:
Iterate over all possible point types (which you can extract with stats if this should be variable) and for each number plot only those points which match the current point type:
stats 'test.data' using 3 nooutput
unset key
set style data points
plot for [i=STATS_min:STATS_max] 'test.data' using 2:($3 == i ? $1 : 1/0) lt 1 pt i ps 2
Use the labels plotting style and a sequence of unicode point symbols from which you select using the value from the third column as index. (use e.g. http://www.shapecatcher.com or http://decodeunicode.org/en/geometric_shapes to find suitable symbols)
unset key
set encoding utf8
symbol(z) = "•✷+△♠□♣♥♦"[int(z):int(z)]
plot 'test.data' using 2:1:(symbol($3)) with labels textcolor lt 1
Is possible if heatmap palette(small rectangle on the right) to be removed?
this is my data
a b c
1 181 80 121 10 34 20
2 18 20 17 20 13 20
3 12 20 5 30 20 20
this is my gnuplot script
set term pos eps font 20
unset key
set nocbtics
set palette rgbformulae -7, 2, -7
set title "Faults"
set size 1, 0.5
set output 'heatmap2.eps'
YTICS="`awk 'BEGIN{getline}{printf "%s ",$1}' 'data2.dat'`"
XTICS="`head -1 'data2.dat'`"
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) i-1 )
set for [i=1:words(YTICS)] ytics ( word(YTICS,i) i-1 )
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) 2*i-1 )
plot "<awk '{$1=\"\"}1' 'data2.dat' | sed '1 d'" matrix every 2::1 w image, \
'' matrix using ($1+1):2:(sprintf('%d', $3)) every 2 with labels
I want to remove the palette because I adjust the ploting colors by percentage of my data. So, I guess the palette on the right my table is now use anymore. Thanks
That is the colorbox. Just use
unset colorbox
to remove it.
I have those data:
Length A B C D E F A_err B_err C_err D_err E_err F_err
17 0,51 1,4 0 0 0 0,07 0,11 0,33 0 0 0 0,08
18 1,33 2,49 1,88 0,51 1,21 0,2 0,18 0,43 1,05 0,5 0,5 0,14
19 2,56 3,83 3,75 0,76 4,22 0,81 0,25 0,53 1,47 0,61 0,92 0,28
20 8,28 7,22 3,44 5,46 5,16 9,19 0,44 0,72 1,41 1,59 1,02 0,89
21 29,96 20 15,78 16,65 13,66 62,58 0,74 1,11 2,82 2,6 1,58 1,49
22 34,16 42,3 56,25 31,51 37,14 16 0,76 1,37 3,84 3,25 2,22 1,13
23 14,23 16,59 17,03 29,86 21,28 1,55 0,56 1,03 2,91 3,2 1,88 0,38
24 6,98 4,39 1,72 12,58 9,6 9,54 0,41 0,57 1,01 2,32 1,35 0,9
25 1,23 1,02 0,16 1,65 4,55 0,05 0,18 0,28 0,31 0,89 0,96 0,07
26 0,45 0,44 0 0,89 1,76 0 0,11 0,18 0 0,66 0,6 0
27 0,18 0,1 0 0 1,04 0 0,07 0,09 0 0 0,47 0
With this code, I obtain a nice histogram with error bars:
set terminal pngcairo enhanced font "arial,15" fontscale 2.0 size 1600,900
set output 'length.png'
set style fill solid 0.7 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles columnhead nobox
set grid ytics
set nokey
set style histogram errorbars linewidth 1 gap 3 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 1,0.5 nomirror offset character 0, 0, 0 autojustify
set xtics norangelimit font ",12"
set xtics ()
set xlabel "n"
set ylabel "Percentage (%)"
set title "length"
set bars 0.3 front
set datafile separator "\t"
set yrange [ 0 : * ] noreverse nowriteback
plot 'length.dat' using 2:8:xtic(1), '' u 3:9:xtic(1), '' u 4:10:xtic(1), '' u 5:11:xtic(1), '' u 6:12:xtic(1), '' u 7:13:xtic(1)
The obtained image is here: http://i.stack.imgur.com/s88QJ.png
But, some error bars just not appear. I notice that is because the error value is below 1. But why ? I'd like all error bars appearing. Is there a problem in the code that forbid errors below 1 to appear ?
Thanks for your help
To me, it looks like your problem is that you're using , as a decimal point character in your file instead of . that gnuplot understands natively. There are two possible solutions. The first I found from googling, but can't test:
set locale
or
set locale "ja_JP.UTF-8" #gnuplot complains this isn't available for me ...
or perhaps set decimalsign local "..."
The second solution is a little less elegant, but it involves converting all of your , to . in your datafile. That's a trivial thing to do using sed:
sed -e 's/,/\./g' length.dat > length2.dat
Now you can just plot using length2.dat and it should work OK (it did for me). As an aside, I think that's quite a nicely colorful plot. The pngcairo terminal does a good job with it.