y2tics and y2label missing in the pm3d map - gnuplot

I am trying to plot a pm3d map using both the primary and secondary axes of gnuplot (version 5.2 patchlevel 8). However, the y2label is missing and the y2tics do not appear after three marks. It would be very helpful if anyone can kindly point out any mistake I have made. The script used is given below and the figure obtained is attached for your reference.Thank you in advance.
set term postscript
set output "map.ps"
set pm3d map corners2color c1
set palette maxcolors 8
set palette defined (0 "#FFFFFF", 1 "#FFFF00", 2 "#FFC020", 3 "#FF69B4", 4 "#4169E1", 5 "#008000", 6 "#20B2AA", 7 "#9ACD32")
set lmargin at screen 0.095
set rmargin at screen 0.795
unset key
# set x-axis
#*******************************************************
set xlabel "Time (ns)" font "Times-italic,18" offset 0, -0.5, 0
set xrange [0.000: 7500.000]
set xtics ("0" 0.000, "50" 1250.0, "100" 2500.0, "150" 3750.0, "200" 5000.0, "250" 6250.0, "300" 7500.0) font "Times-italic,16"
# set y-axis
#*******************************************************
set ylabel "Peptide Number" font "Times-italic,18" offset -1.2, 1, 0
set yrange [2.0: 36.0]
set ytics ("1" 5.0, "2" 12.0, "3" 19.0, "4" 26.0, "5" 33.0) font "Times-italic,16"
set ytics nomirror
set y2label "Residue Number" font "Times-italic,18" offset -2.5, 0, 0
set y2range [2.0: 36.0]
set y2tics nomirror ("1" 2.0, "7" 8.0, "1" 9.0 , "7" 15.0, "1" 16.0, "7" 22.0, "1" 23.0, "7" 29.0, "1" 30.0, "7" 36.0) font "Times-italic,14"
# set cb-axis
#*******************************************************
set colorbox vertical user origin 0.890, .147 size .04, .73
set cbrange [-0.500: 7.500]
set cbtics 0.000, 7.000, 1.0
set cbtics("None" 0.000,"Ext" 1.000,"Bridge" 2.000,"3-10" 3.000,"Alpha" 4.000,"Pi" 5.000,"Turn" 6.000,"Bend" 7.000)
set link y2
splot "-" with pm3d title "map.gnu"
1.000 1.000 2
1.000 2.000 0
1.000 3.000 0
1.000 4.000 0
1.000 5.000 0
1.000 6.000 3
1.000 7.000 0
1.000 8.000 0
1.000 9.000 0
1.000 10.000 0
1.000 11.000 0
1.000 12.000 0
1.000 13.000 0
1.000 14.000 1
1.000 15.000 0
1.000 16.000 0
1.000 17.000 6
1.000 18.000 0
1.000 19.000 7
1.000 20.000 0
1.000 21.000 0
1.000 22.000 4
1.000 23.000 0
1.000 24.000 0
1.000 25.000 6
1.000 26.000 6
1.000 27.000 5
1.000 28.000 0
1.000 29.000 0
1.000 30.000 4
1.000 31.000 0
1.000 32.000 0
1.000 33.000 7
1.000 34.000 0
1.000 35.000 0
1.000 36.000 0
2.000 1.000 0
2.000 2.000 0
2.000 3.000 0
2.000 4.000 2
2.000 5.000 4
2.000 6.000 5
2.000 7.000 0
2.000 8.000 0
2.000 9.000 6
2.000 10.000 0
2.000 11.000 0
2.000 12.000 0
2.000 13.000 7
2.000 14.000 0
2.000 15.000 0
2.000 16.000 0
2.000 17.000 0
2.000 18.000 0
2.000 19.000 8
2.000 20.000 0
2.000 21.000 0
2.000 22.000 0
2.000 23.000 0
2.000 24.000 9
2.000 25.000 6
2.000 26.000 6
2.000 27.000 6
2.000 28.000 0
2.000 29.000 5
2.000 30.000 0
2.000 31.000 0
2.000 32.000 0
2.000 33.000 7
2.000 34.000 0
2.000 35.000 0
2.000 36.000 0

I assume from your code that you have simple x,y,z data.
x with sample numbers from 0 to 7500 which correspond to 0 to 300 ns.
y in the range from 1 to 6
z in the range from 0 to 7
For the example below I create some random test data.
I can reproduce your issue with splot ... with pm3d, however, do not (yet) have a solution.
Therefore, my suggestion would be to use plot ... with boxxerror.
If you plot that many boxes, your PostScript file probably will get pretty large. So, I would recommend to use a pixel graphic with sufficient resolution, e.g. set term pngacairo size 1400,1000.
Code:
### "plot ... with boxxyerror" instead of "splot ... with pm3d"
reset session
set palette maxcolors 8
set palette defined (0 "#FFFFFF", 1 "#FFFF00", 2 "#FFC020", 3 "#FF69B4", 4 "#4169E1", 5 "#008000", 6 "#20B2AA", 7 "#9ACD32")
# create some random test data
set print $Data
do for [i=1:7500] for [j=1:5] {
print sprintf("%g %g %g", i, int(rand(0)*6)+(j-1)*7+2, int(rand(0)*8))
}
set print
set xrange [0:300]
XScale = 300/7500. # scaling between sample and x-axis units
set yrange [1: 37]
set for [i=1:5] ytics (sprintf("%g",i) i*7-2)
set ytics nomirror
set y2range [1: 37]
set for [i=1:5] y2tics ("1" i*7-5, "7" i*7+1)
set y2tics nomirror
set link y2
set cbrange [-0.500: 7.500]
set cbtics 0.000, 7.000, 1.0
myCbTics = "None Ext Bridge 3-10 Alpha Pi Turn Bend"
set for [i=0:words(myCbTics)] cbtics (word(myCbTics,i+1) i)
set key noautotitle
set tics out
set style fill solid 1.0
plot $Data u ($1*XScale):2:($1*XScale):(($1+1)*XScale):($2):($2+1):3 w boxxy palette z
### end of code
Result:

I do not know why the default link command set link y2 is failing, but it seems to work if you explicitly give the longer form set link y2 via y inv y.
Aside from that, note that set link y2 command will immediately replace any limits on y2range with limits matching the y1 range, so the set y2range command in your script as shown has no effect.

Related

gnuplot: how to plot color squares for each month's temperature?

I would like to plot the following figure (from Fundamentals of Data Visualization) using gnuplot:
I expect the data for each location is something like:
# month temperature
01 60.0
02 78.0
03 90.0
...
12 78.0
Here is what I tried. For simplicity, I have transposed the data into a matrix.
$data << EOD
1.50 1.57 1.85 2.15 1.87 1.05 1.70 1.65 1.97 1.71 1.53 1.15
4.44 4.71 4.74 3.50 3.43 4.98 4.29 4.55 3.93 3.34 3.74 4.88
8.55 9.59 5.65 0.13 9.33 4.70 8.94 7.74 4.49 6.26 0.96 1.20
EOD
unset border
unset ytics
set xlabel 'month'
set palette rgbformula -7,2,-7
set cbrange [0:10]
set cblabel "precipitation"
set xrange [-0.5:11.5]
set yrange [-0.5:2.5]
set xtics ("Jan" 0, "Feb" 1, "Mar" 2, "Apr" 3, "May" 4, \
"Jun" 5, "Jul" 6, "Aug" 7, "Sep" 8, "Oct" 9, "Nov" 10, "Dec" 11)
plot $data matrix with image
But the effect is far from satisfactory. For example, How to generate clear borders between squares?
The plotting style with image probably cannot have borders. So, I would use the versatile style with boxxyerror.
Furthermore, instead of matrix format I would add a line header and loop through the columns (since there will be always 12 months)
Check the following example as well as help boxxyerror, help size, help xticlabels and help strftime for further reading.
If you have your data in separate files you would have to modify the script accordingly.
Script:
### plotting style boxxyerror as replacement for "with image"
reset session
$Data << EOD
# location Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Atlantis 1.50 1.57 1.85 2.15 1.87 1.05 1.70 1.65 1.97 1.71 1.53 1.15
Mordor 4.44 4.71 4.74 3.50 3.43 4.98 4.29 4.55 3.93 3.34 3.74 4.88
Wonderland 8.55 9.59 5.65 0.13 9.33 4.70 8.94 7.74 4.49 6.26 0.96 1.20
EOD
unset border
set xlabel 'month'
set xrange [0.5:12.5]
set yrange [:] reverse
set ytics
set palette rgbformula -7,2,-7
set cbrange [0:10]
set cblabel "precipitation"
MonthName(n) = strftime("%b",24*3600*28*n) # get the month name from 1..12
set key noautotitle
set style fill solid 1.0 border rgb "white"
set size ratio -1 # make the boxes squares
plot for [i=1:12] $Data u (i):0:(0.5):(0.5):i+1: \
xtic(MonthName(i)):ytic(1) w boxxy fc palette lw 2
### end of code
Result:

Gnuplot pm3d: 'NaN value' removes all surrounding rectangles

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

Ploting a GIF from a single data file

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:

How to import data from multiple excel sheets in GAMS using loops?

I want to import the data for a three-dimensional parameter p(i,j,k) that is stored in in k excel sheets but GAMS does not let me use dollar control statements in loops. Is there any way to do that using loops or other flow control statements like 'for' or 'while'?
I need to do something like this but it is seemingly impossible:
loop(k,
$call gdxxrw Data.xlsx par=temp rng=k!A1:Z20 rdim=1 cdim=1
$gdxin Data.gdx
$load temp
$gdxin
p(i,j,k)=temp(i,j);
);
Suppose each sheet looks like:
(only difference is I use 2's in sheet2 and 3's in sheet3).
To read this do:
$set xls d:\tmp\test2.xlsx
$set gdx s.gdx
set
i /i1*i3/
j /j1*j5/
k 'sheet names' /Sheet1*Sheet3/
;
parameter
s(i,j) 'single sheet'
a(i,j,k) 'all data'
;
file f /task.txt/;
loop(k,
putclose f,'par=s rng=',k.tl:0,'!a1 rdim=1 cdim=1'/
execute 'gdxxrw i=%xls% o=%gdx% #task.txt trace=2';
execute_loaddc '%gdx%',s;
a(i,j,k) = s(i,j);
);
display a;
My results are:
---- 23 PARAMETER a all data
sheet1 sheet2 sheet3
i1.j1 1.000 2.000 3.000
i1.j2 1.000 2.000 3.000
i1.j3 1.000 2.000 3.000
i1.j4 1.000 2.000 3.000
i1.j5 1.000 2.000 3.000
i2.j1 1.000 2.000 3.000
i2.j2 1.000 2.000 3.000
i2.j3 1.000 2.000 3.000
i2.j4 1.000 2.000 3.000
i2.j5 1.000 2.000 3.000
i3.j1 1.000 2.000 3.000
i3.j2 1.000 2.000 3.000
i3.j3 1.000 2.000 3.000
i3.j4 1.000 2.000 3.000
i3.j5 1.000 2.000 3.000

Empty plot gnuplot

I am facing some trouble to make a simple plot.
My .gnu file return an empty plot, like this :
I want a heat map, the format of my data is X Y Z in the .gnu file and the header is like this :
cat plot.gnu | head -n 10 :
set size square
set pm3d map corners2color c1
set xlabel ""
set ylabel ""
set yrange [ 0.000:3003.000]
set xrange [ 0.000:3003.000]
splot "-" with pm3d title "plot.gnu"
1.000 1.000 0
1.000 2.000 0
1.000 3.000 0
and the footer is like this :
cat plot.gnu | tail -n 10
3002.000 2996.000 0
3002.000 2997.000 0
3002.000 2998.000 0
3002.000 2999.000 0
3002.000 3000.000 0
3002.000 3001.000 0
3002.000 3002.000 0
end
pause -1
EDIT : A shorter script could be :
set size square
set pm3d map corners2color c1
set xlabel ""
set ylabel ""
set yrange [ 0.000:4.000]
set xrange [ 0.000:4.000]
splot "-" with pm3d title "plot.gnu"
1.000 1.000 1
1.000 2.000 2
1.000 3.000 4
1.000 4.000 5
2.000 1.000 1
2.000 2.000 0
2.000 3.000 3
2.000 4.000 1
3.000 1.000 1
3.000 2.000 0
3.000 3.000 3
3.000 4.000 0
4.000 1.000 9
4.000 2.000 0
4.000 4.000 3
4.000 4.000 2
end
pause -1
Do you have an idea ?
Thanks
The short script gives the warning
Warning: Single isoline (scan) is not enough for a pm3d plot.
Hint: Missing blank lines in the data file? See 'help pm3d' and FAQ.
And indeed, your data must be structured differently: isolines, i.e. parts with equal x-values (in your first column), must be separated by single empty lines:
set size square
set pm3d map corners2color c1
set autoscale xfix
set autoscale yfix
splot "-" with pm3d title "plot.gnu"
1.000 1.000 1
1.000 2.000 2
1.000 3.000 4
1.000 4.000 5
2.000 1.000 1
2.000 2.000 0
2.000 3.000 3
2.000 4.000 1
3.000 1.000 1
3.000 2.000 0
3.000 3.000 3
3.000 4.000 0
4.000 1.000 9
4.000 2.000 0
4.000 4.000 3
4.000 4.000 2
e
pause -1

Resources