In principle the problem is the same like in matlab2tikz imagesc TikZ/pgfplots equivalent
Can somebody tell me how to adopt this snippet to plot non-symmetric matrices but with squared axis (without any gaps inside)
As it should not look like, because of the gaps:
As it should look not like, because of the rectangle axis:
Snipped:
\documentclass[border=5mm]{standalone}
\usepackage{xcolor}
\definecolor{cr3}{RGB}{177,11,69}
\definecolor{cr2}{RGB}{210,210,210}
\definecolor{cr1}{RGB}{121,154,153}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{%
compat=newest,
tick label style={font=\small},
label style={font=\footnotesize},
legend style={font=\scriptsize,fill=none,draw=none},
every axis legend/.append style={legend image code/.code={\draw[mark repeat=2,mark phase=2,##1]plot coordinates {(0cm,0cm) (0.1cm,0cm) (0.2cm,0cm)};}},
}%
%*** matrix-plot style
\pgfplotsset{%
matrix plot/.style = {%
axis on top,
clip marker paths = true,
scale only axis,
% height = \nYdata//\nXdata/*\pgfkeysvalueof{/pgfplots/width},
enlarge x limits = {rel=0.5/\nXdata/},
enlarge y limits = {rel=0.5/\nYdata/},
scatter/use mapped color = {draw=mapped color, fill=mapped color},
scatter,
point meta = explicit,
mark = square*,
cycle list = {%
mark size=0.5*\pgfkeysvalueof{/pgfplots/width}/\nXdata/
}
},
}%
%*** number definition
\pgfkeys{%
/pgf/number format/set thousands separator={},
/pgf/number format/set decimal separator={.}
}%
%*** data table information
\usepackage{pgfplotstable}
\pgfplotstableset{%
col sep=semicolon,
x index=0,
y index=1,
header=false
}%
\begin{document}
\begin{tikzpicture}
%*** definition of datasize
\def\nXdata/{20},
\def\nYdata/{6},
%*** definition of limits
\def\min/{0.5},
\def\max/{1.5},
\def\lb/{1.0},
\def\ub/{1.0},
%*** axis
\begin{axis}[
width=5cm,
height=5cm,
matrix plot,
point meta min={\min/},
point meta max={\max/},
colormap={UIBK}{[0.1]
color(\min/-\min/)=(cr1);
color(\lb/-\min/)=(cr2);
color(\ub/-\min/)=(cr2);
color(\max/-\min/)=(cr3)},
%*** colorbar
colorbar horizontal,
colorbar style = {%
at={(0.0,1.30)},
anchor=south west,
width=1.0*\pgfkeysvalueof{/pgfplots/parent axis width},
height=0.3cm,
xmin=\min/,
xmax=\max/,
xtick={\min/,\lb/,\ub/,\max/},
mark = square*,},
colorbar sampled line,
%*** x-axis
xlabel = {$n$},
xmin = 1,
xmax = 20,
xtick = {1,5,10,15,20},
%*** y-axis
ylabel = {$\tau$},
ymin = 1,
ymax = 6,
ytick = {1,2,3,4,5,6},
yticklabels = {0.10,0.12,0.14,0.16,0.18,0.20},
]
\addplot table [meta index=2] {1.000000;1.000000;1.051819
1.000000;2.000000;1.000000
1.000000;3.000000;1.000000
1.000000;4.000000;1.000000
1.000000;5.000000;1.012168
1.000000;6.000000;0.988435
2.000000;1.000000;0.953648
2.000000;2.000000;0.945830
2.000000;3.000000;0.967785
2.000000;4.000000;0.980390
2.000000;5.000000;0.957779
2.000000;6.000000;0.973894
3.000000;1.000000;0.962710
3.000000;2.000000;0.949404
3.000000;3.000000;0.959728
3.000000;4.000000;0.972972
3.000000;5.000000;0.963546
3.000000;6.000000;0.979361
4.000000;1.000000;0.959866
4.000000;2.000000;0.984708
4.000000;3.000000;0.961893
4.000000;4.000000;0.998287
4.000000;5.000000;0.968716
4.000000;6.000000;0.962727
5.000000;1.000000;0.973517
5.000000;2.000000;0.975561
5.000000;3.000000;0.976335
5.000000;4.000000;0.976228
5.000000;5.000000;0.983381
5.000000;6.000000;0.968988
6.000000;1.000000;0.966111
6.000000;2.000000;0.984690
6.000000;3.000000;0.947801
6.000000;4.000000;0.984505
6.000000;5.000000;0.964116
6.000000;6.000000;0.972827
7.000000;1.000000;0.993063
7.000000;2.000000;0.953702
7.000000;3.000000;0.996289
7.000000;4.000000;0.970655
7.000000;5.000000;0.957275
7.000000;6.000000;0.925806
8.000000;1.000000;0.958390
8.000000;2.000000;0.998144
8.000000;3.000000;0.974472
8.000000;4.000000;0.954414
8.000000;5.000000;0.949770
8.000000;6.000000;0.918929
9.000000;1.000000;0.998319
9.000000;2.000000;0.980637
9.000000;3.000000;0.966380
9.000000;4.000000;0.973852
9.000000;5.000000;0.931611
9.000000;6.000000;0.939964
10.000000;1.000000;1.009831
10.000000;2.000000;0.997056
10.000000;3.000000;0.971533
10.000000;4.000000;0.950970
10.000000;5.000000;0.984151
10.000000;6.000000;0.939601
11.000000;1.000000;0.991757
11.000000;2.000000;0.986907
11.000000;3.000000;0.970439
11.000000;4.000000;1.000952
11.000000;5.000000;0.982607
11.000000;6.000000;0.963821
12.000000;1.000000;1.030766
12.000000;2.000000;1.012735
12.000000;3.000000;1.000013
12.000000;4.000000;1.014096
12.000000;5.000000;0.973391
12.000000;6.000000;0.984517
13.000000;1.000000;1.020537
13.000000;2.000000;0.997647
13.000000;3.000000;1.035671
13.000000;4.000000;0.998183
13.000000;5.000000;0.995325
13.000000;6.000000;0.975726
14.000000;1.000000;1.033529
14.000000;2.000000;1.026951
14.000000;3.000000;1.039208
14.000000;4.000000;1.001587
14.000000;5.000000;0.985112
14.000000;6.000000;1.029229
15.000000;1.000000;1.004259
15.000000;2.000000;1.049424
15.000000;3.000000;1.017412
15.000000;4.000000;1.006954
15.000000;5.000000;1.012810
15.000000;6.000000;1.084488
16.000000;1.000000;1.026232
16.000000;2.000000;1.073393
16.000000;3.000000;1.032529
16.000000;4.000000;1.010247
16.000000;5.000000;1.031920
16.000000;6.000000;1.059238
17.000000;1.000000;1.049910
17.000000;2.000000;1.027786
17.000000;3.000000;1.018022
17.000000;4.000000;1.015627
17.000000;5.000000;1.113215
17.000000;6.000000;1.080651
18.000000;1.000000;1.065341
18.000000;2.000000;1.041362
18.000000;3.000000;1.011830
18.000000;4.000000;1.058460
18.000000;5.000000;1.069346
18.000000;6.000000;1.058428
19.000000;1.000000;1.095343
19.000000;2.000000;1.021611
19.000000;3.000000;1.031146
19.000000;4.000000;1.122735
19.000000;5.000000;1.098571
19.000000;6.000000;1.088736
20.000000;1.000000;1.065167
20.000000;2.000000;1.005796
20.000000;3.000000;1.051143
20.000000;4.000000;1.078253
20.000000;5.000000;1.080351
20.000000;6.000000;1.069805
};
\end{axis}
\end{tikzpicture}
\end{document}
EDIT:
color modification implemented (Scaling colormaps with pgfplots).

