I would like to plot a pm3d map, where data points are not equidistant on the axis.
Since the spacings for the x and y axis are identical, it is symmetrical, though.
The problem is whenever a value is "NaN", all of the four surrounding rectangles
are not plotted. In the data file below, this happens, for example, at (x,y)=(0.14,0.33) .
If the value is not 'NaN', then the four rectangles reappear.
I discovered this problem, when I tried to plot only the values >0 or <0, where the same happens.
I tried to search the documentation and the internet, but couldn't find anything on this.
Are there any solutions to this?
Plotscript:
set view map
set pm3d at b
set style data pm3d
set pm3d corners2color c1
set size ratio 1
set autoscale fix
set cbrange [-25:25]
set palette defined (-25 "blue", 0 "white", 25 "red")
set term png
set output "test.png"
splot "data.txt" u 1:2:3 notitle
set output
Data file:
0.0 0.0 1
0.0 0.08 -2
0.0 0.14 3
0.0 0.33 -4
0.0 0.46 5
0.0 0.55 5
0.08 0.0 -6
0.08 0.08 7
0.08 0.14 -8
0.08 0.33 9
0.08 0.46 -10
0.08 0.55 -10
0.14 0.0 11
0.14 0.08 -12
0.14 0.14 13
0.14 0.33 NaN
0.14 0.46 15
0.14 0.55 15
0.33 0.0 -16
0.33 0.08 17
0.33 0.14 -18
0.33 0.33 19
0.33 0.46 -20
0.33 0.55 -20
0.46 0.0 21
0.46 0.08 -22
0.46 0.14 23
0.46 0.33 -24
0.46 0.46 25
0.46 0.55 25
0.55 0.0 21
0.55 0.08 -22
0.55 0.14 23
0.55 0.33 -24
0.55 0.46 25
0.55 0.55 25
Thanks to the comment by #theozh I figured out a solution to this problem.
I adopted the script by #theozh under Plotting Heatmap with different column/line widths to the form below. This yields for the file
1 -6 11 -16 21
-2 7 -12 17 -22
3 -8 13 -18 23
-4 9 NaN 19 -24
5 -10 15 -20 25
this plot.
This is the best solution, because the data has this format anyway and the coordinates are a different file that I read in.
Plotscript:
CoordsX = "0.04 0.11 0.24 0.40 0.51"
CoordsY = "0.04 0.11 0.24 0.40 0.51"
dimX = words(CoordsX)
dimY = words(CoordsY)
dx(i) = (word(CoordsX,i)-word(CoordsX,i-1))*0.5
dy(i) = (word(CoordsY,i)-word(CoordsY,i-1))*0.5
ndx(i,j) = word(CoordsX,i) - (i-1<1 ? dx(i+1) : dx(i))
pdx(i,j) = word(CoordsX,i) + (i+1>ColCount ? dx(i) : dx(i+1))
ndy(i,j) = word(CoordsY,j) - (j-1<1 ? dy(j+1) : dy(j))
pdy(i,j) = word(CoordsY,j) + (j+1>RowCount ? dy(j) : dy(j+1))
set xrange[ndx(1,1):pdx(ColCount,1)]
set yrange[ndy(1,1):pdy(1,RowCount)]
set tic out
max = 25
set cbrange [-max:max]
set palette defined (-max "blue", 0 "white", max "red")
set term png
set output "test.png"
plot for [i=1:dim_x] file u (real(word(CoordsX,i))):1:(ndx(i,int($0))):(pdx(i,int($0))):(ndy(i,int($0+1))):(pdy(i,int($0+1))):i with boxxyerror fs solid 1.0 palette notitle
set output
### end of code
Hello guys I am new to gnuplot and im looking to plot a gif representing the evolution of some probabilities with cycles.
My data file is structured like this:
0 0 1 3.56133e-008 2 1.18619e-007 3 3.75373e-007 ...
0 0 1 3.56133e-008 2 2.26246e-008 3 1.44814e-007 ...
The first row represents cycle 0 while the first and second column represents position 0 and its probability. The number of positions is large so doing it manually will take too much time.
I got this for now but i dont really know how to do the for loop with this kind of data.
set terminal gif
set output 'Probability.gif'
stats 'Probability.txt' nooutput
set xlabel 'Position'
set ylabel 'Probability'
set yrange [0:1]
set style fill solid border -1
unset key
Thanks beforehand any help is apreciated.
What you can do is to extract all x and y pairs from each row and plot it into a table. Actually, gnuplot prefers to have data in columns. Then plot this table to the gif terminal with the option animated. Check help gif. If you have a file remove the datablock $Data <<EOD ... EOD and in the code replace (2 times) $Data by "YourFilename".
Code:
### animated rows x0 y0 x1 y1 x2 y2
reset session
$Data <<EOD
0 0.00 1 0.10 2 0.20 3 0.40 4 0.20 5 0.10 6 0.00
0 0.00 1 0.08 2 0.18 3 0.48 4 0.18 5 0.08 6 0.00
0 0.00 1 0.05 2 0.16 3 0.58 4 0.16 5 0.05 6 0.00
0 0.00 1 0.08 2 0.18 3 0.48 4 0.18 5 0.08 6 0.00
0 0.00 1 0.10 2 0.20 3 0.40 4 0.20 5 0.10 6 0.00
EOD
stats $Data nooutput
ColCount = STATS_columns
RowCount = STATS_records
set xrange[0:6]
set yrange[0:1]
set terminal gif size 400,400 animate delay 50 optimize
set output "myAnimation.gif"
do for [j=0:RowCount-1] {
set table $Extract
plot for [i=1:ColCount/2] $Data u (column(2*i-1)):(column(2*i)) every ::j::j w table
unset table
plot $Extract u 1:2 w lp pt 7 lw 2 title sprintf("Row %d",j)
}
set output
### end of code
Result:
I am simulating something and want to figure out the influence of two parameters. Therefore I vary them both and look for the result on each pair of parameter values and get a result like:
0 1000 2000 3000 4000 5000 ....
0 13.2 14.8 19.9 25.5 27.3 ...
1000 21.3 25.9 32.3 etc.
2000 etc.
3000
4000
....
To visualize them, I use gnuplot, creating a heatmap, which works perfectly fine, showing me colors and height:
reset
set terminal qt
set title "Test"
unset key
set tic scale 0
set palette rgbformula 7,5,15
set cbrange [0:100]
set cblabel "Transmission"
set pm3d at s interpolate 1,1
unset surf
set xlabel "U_{Lense} [V]"
set ylabel "E_{Start} [eV]"
set datafile separator "\t"
splot "UT500test.csv" matrix rowheaders columnheaders
Now I want to look more detailed on some areas on my heatmap, and vary my parameters in steps of 100 difference, not 1000 as shown in the table above. But because the simulation takes quite a long time, I just do this for some areas, so my table looks like this:
0 1000 2000 2100 2200 2300 2400 ... 2900 3000 4000 ...
...
Now I want to show this in the heatmap, too. But everytime I tried this, all the bins on the heatmap, no matter if 1000 or 100 difference are of the same width. But I want the ones with 100 difference to be only 1/10 of the width of the 1000 differences. Is there a possibility to do this?
The extra steps with stats are not necessary.
You can access the true coordinates directly as a nonuniform matrix:
set offset 100,100,100,100
plot $Data matrix nonuniform using 1:2:3 with points pt 5 lc palette
The missing piece is to fill in the full area rather than plotting single points. You can do this using pm3d:
set pm3d corners2color mean
set view map
splot $Data matrix nonuniform with pm3d
The colors do not match the previous plot because pm3d considers all 4 corners of each box when assigning a color. I told it to take the mean value (that's the default) but many other variants are possible. You could smooth the coloring further with set pm3d interpolate 3,3
You could do something with plotting style with boxxyerror. It's pretty straightforward, except the way to get the x-coordinates into an array which will be used later during plotting. Maybe, there are smarter solutions.
Script:
### heatmap with irregular spacing
reset session
unset key
$Data <<EOD
0.00 0.00 1000 2000 2100 2200 2300 2400 3000 4000
1000 0.75 0.75 0.43 0.34 0.61 0.74 0.66 0.97 0.58
1100 0.82 0.90 0.18 0.12 0.87 0.15 0.01 0.57 0.97
1200 0.10 0.15 0.68 0.73 0.55 0.07 0.98 0.89 0.01
1300 0.67 0.38 0.41 0.85 0.37 0.45 0.49 0.21 0.98
1400 0.76 0.53 0.68 0.09 0.22 0.40 0.59 0.33 0.08
2000 0.37 0.32 0.30 NaN 0.33 NaN 0.73 0.94 0.96
3000 0.07 0.61 0.37 0.54 0.32 0.28 0.62 0.51 0.48
4000 0.79 0.98 0.78 0.06 0.16 0.45 0.83 0.50 0.10
5000 0.49 0.95 0.29 0.59 0.55 0.88 0.29 0.47 0.93
EOD
stats $Data nooutput
BoxHalfWidth=50
# put first row into array
array ArrayX[STATS_columns]
set table $Dummy
plot for [i=1:STATS_columns] $Data u (ArrayX[i]=column(i)) every ::0::0 with table
unset table
plot for [i=2:STATS_columns] $Data u (ArrayX[i]):1:(BoxHalfWidth):(BoxHalfWidth):i every ::1 with boxxyerror fs solid 1.0 palette
### end of script
Result:
Edit:
With a little bit more effort you can as well generate a plot which covers the whole area.
In contrast to the simpler code from #Ethan, the recangles are centered on the datapoint coordinates and have the color of the actual datapoint z-value. Furthermore, the datapoint (2200,2000) is also plotted. The borders of the rectangles are halfway between matrix points. The outer rectangles have dimensions equal to the x and y distance to the next inner matrix point.
Revision: (simplified version, works for gnuplot>=5.0.1)
The following solution works for gnuplot 5.0.1, but not for 5.0.0 (haven't found out yet why).
There will be a warning: warning: matrix contains missing or undefined values which can be ignored.
I noticed that there seems to be a bug(?!) with the matrix column index, but you can fix it with:
colIdxFix(n) = (r0=r1,r1=column(-1),r0==r1?c=c+1:c=1) # fix for missing column index in a matrix
plot r1=c=0 $Data nonuniform matrix u 1:2:(colIdxFix(0)) ....
Script: (works with gnuplot>=5.0.1)
### heatmap with irregular spacing with filled area
# compatible with gnuplot>=5.0.1
reset session
$Data <<EOD
0.00 0.00 1000 2000 2100 2200 2300 2400 3000 4000
1000 0.75 0.75 0.43 0.34 0.61 0.74 0.66 0.97 0.58
1100 0.82 0.90 0.18 0.12 0.87 0.15 0.01 0.57 0.97
1200 0.10 0.15 0.68 0.73 0.55 0.07 0.98 0.89 0.01
1300 0.67 0.38 0.41 0.85 0.37 0.45 0.49 0.21 0.98
1400 0.76 0.53 0.68 0.09 0.22 0.40 0.59 0.33 0.08
2000 0.37 0.32 0.30 NaN 0.33 NaN 0.73 0.94 0.96
3000 0.07 0.61 0.37 0.54 0.32 0.28 0.62 0.51 0.48
4000 0.79 0.98 0.78 0.06 0.16 0.45 0.83 0.50 0.10
5000 0.49 0.95 0.29 0.59 0.55 0.88 0.29 0.47 0.93
EOD
# get irregular x- and y-values into string
Xs = Ys = ""
stats $Data matrix u ($1==0 ? Ys=Ys.sprintf(" %g",$3) : 0, \
$2==0 ? Xs=Xs.sprintf(" %g",$3) : 0) nooutput
# box extension d in dn (negative) and dp (positive) direction
d(vs,n0,n1) = abs(real(word(vs,n0+1))-real(word(vs,n1+1)))/2.
dn(vs,n) = (n==1 ? (n0=1,n1=2) : (n0=n,n1=n-1), -d(vs,n0,n1))
dp(vs,n) = (Ns=words(vs)-1, n>=Ns ? (n0=Ns-1,n1=Ns) : (n0=n,n1=n+1), d(vs,n0,n1))
unset key
set offset 1,1,1,1
set style fill solid 1.0
colIdxFix(n) = (r0=r1,r1=column(-1),r0==r1?c=c+1:c=1) # fix for missing column index in a matrix (bug?!)
plot r1=c=0 $Data nonuniform matrix u 1:2:($1+dn(Xs,colIdxFix(0))):($1+dp(Xs,c)): \
($2+dn(Ys,int(column(-1))+1)):($2+dp(Ys,int(column(-1))+1)):3 w boxxy palette
### end of script
Result:
Edit2: (I leave this here for gnuplot 5.0.0)
Just for fun, here is the "retro-version" for gnuplot 5.0:
gnuplot5.0 does not support arrays. Although, gnuplot5.0 supports datablocks, but apparently indexing like $Datablock[1] does not work. So, the workaround-around is to put the matrix X,Y coordinates into strings CoordsX and CoordsY and get the coordinates with word(). If there is not another limitation with string and word(), the following worked with gnuplot5.0 and gave the same result as above.
Script:
### heatmap with irregular spacing with filled area
# compatible with gnuplot 5.0
reset session
unset key
$Data <<EOD
0.00 0.00 1000 2000 2100 2200 2300 2400 3000 4000
1000 0.75 0.75 0.43 0.34 0.61 0.74 0.66 0.97 0.58
1100 0.82 0.90 0.18 0.12 0.87 0.15 0.01 0.57 0.97
1200 0.10 0.15 0.68 0.73 0.55 0.07 0.98 0.89 0.01
1300 0.67 0.38 0.41 0.85 0.37 0.45 0.49 0.21 0.98
1400 0.76 0.53 0.68 0.09 0.22 0.40 0.59 0.33 0.08
2000 0.37 0.32 0.30 NaN 0.33 NaN 0.73 0.94 0.96
3000 0.07 0.61 0.37 0.54 0.32 0.28 0.62 0.51 0.48
4000 0.79 0.98 0.78 0.06 0.16 0.45 0.83 0.50 0.10
5000 0.49 0.95 0.29 0.59 0.55 0.88 0.29 0.47 0.93
EOD
stats $Data nooutput
ColCount = int(STATS_columns-1)
RowCount = int(STATS_records-1)
# put first row and column into arrays
CoordsX = ""
set table $Dummy
set xrange[0:1] # to avoid warnings
do for [i=2:ColCount+1] {
plot $Data u (Value=column(i)) every ::0::0 with table
CoordsX = CoordsX.sprintf("%g",Value)." "
}
unset table
CoordsY = ""
set table $Dummy
do for [i=1:RowCount] {
plot $Data u (Value=$1) every ::i::i with table
CoordsY= CoordsY.sprintf("%g",Value)." "
}
unset table
dx(i) = (word(CoordsX,i)-word(CoordsX,i-1))*0.5
dy(i) = (word(CoordsY,i)-word(CoordsY,i-1))*0.5
ndx(i,j) = word(CoordsX,i) - (i-1<1 ? dx(i+1) : dx(i))
pdx(i,j) = word(CoordsX,i) + (i+1>ColCount ? dx(i) : dx(i+1))
ndy(i,j) = word(CoordsY,j) - (j-1<1 ? dy(j+1) : dy(j))
pdy(i,j) = word(CoordsY,j) + (j+1>RowCount ? dy(j) : dy(j+1))
set xrange[ndx(1,1):pdx(ColCount,1)]
set yrange[ndy(1,1):pdy(1,RowCount)]
set tic out
plot for [i=2:ColCount+1] $Data u (real(word(CoordsX,i-1))):1:(ndx(i-1,int($0))):(pdx(i-1,int($0))): \
(ndy(i-1,int($0+1))):(pdy(i-1,int($0+1))):i every ::1 with boxxyerror fs solid 1.0 palette
### end of script
From How to get a radial(polar) plot using gnu plot?
My data:
theta dB
0 0.00
30 0.09
60 -0.26
90 -0.26
120 -0.35
150 -0.35
180 -0.35
210 -0.35
240 -0.26
270 -0.09
300 -0.26
330 0.00
360 0.00
Axis will not start at 0 but it start at -2 to 0. How can i fix this code?
The range in polar mode is controlled by set rrange:
set polar
set grid polar
set angles degree
set size ratio 1
unset border
unset xtics
unset ytics
set rrange [-2:0]
plot 'file.txt' with lines
Result with 4.6.3 is:
I need to visualize some data I have, with box and whisker plots, and I'd like to do it in GNUPLOT. So far I have converted my data to what I have understood is needed for GNU plot. The minimum, first quartile, median, third quartile and max.
This is the data I have:
#x min Q1 median q3 max width label
1 9.9 10.25 10.7 10.975 11.3 0.3 100
2 23.5 25.525 26.05 27.85 29.1 0.3 200
3 37.5 40.8 43.65 44.35 45.7 0.3 300
4 55 58.25 58.65 61.875 65.9 0.3 400
5 71.3 73.65 75.25 77.4 80.1 0.3 500
6 73.6 83.85 86.05 88.775 97.5 0.3 600
7 85.8 89.45 97.3 103.75 106 0.3 700
8 102 111 112 115.5 119 0.3 800
9 116 127 128 134 141 0.3 900
10 126 134 136 140.25 146 0.3 1000
11 144 149 152 156.25 165 0.3 1100
12 144 151.25 154 158 166 0.3 1200
13 138 157.25 159 162 171 0.3 1300
14 155 161.25 165.5 170 173 0.3 1400
15 158 171 172.5 177.5 182 0.3 1500
I have made this graph in Excel
But I need to have more graphs in the same image, which is something I cannot do in Excel. I have been messing around with GNUPLOT for a couple of hours, trying to use candlesticks, but all the graphs I get are wrong!
I've uploaded my data-file to DROPBOX https://dl.dropboxusercontent.com/u/12340447/data.txt
Any help is greatly appreciated!
EDIT:
I should probably include the script I currently have
set bars 2.0
set style fill empty
plot 'data.txt' using 1:3:2:6:5:xticlabels(7) with candlesticks title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4 with candlesticks lt -1 notitle
This gives the ouput
There's a few thing wrong with the picture: First of all the labels are wrong. They all say 0.3, but that's supposed to the the width of the boxplots. I'd also like to add a line (as in the excel) from each mean value, marked with a dot or cross or something.. Basically, make it look a little more like the Excel output.
Again - any help is greatly appreceiated!
The labels were wrong because they need to come from column 8 (xticlabels(8)) in the data.
The last line adds a blue line (lt 3), with diamond points (pt 13)
set bars 2.0
set style fill empty
plot 'data.txt' using 1:3:2:6:5:xticlabels(8) with candlesticks title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4 with candlesticks lt -1 notitle, \
'' using 1:4 with linespoints lt 3 pt 13 notitle