我想使用简单的格式为某个简单体素网格上的字段值着色,例如
pointx pointy 值。我从
前面的示例运行良好,但我无法将矩阵图与网格线对齐。我想在同一个图形轮廓线上绘图。代码是
\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{
width=8cm,
height=8cm,
compat=1.11,
colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0.15)},
xtick=\empty,
ytick=\empty
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
enlargelimits=false,
xlabel style={font=\footnotesize},
ylabel style={font=\footnotesize},
legend style={font=\footnotesize},
xticklabel style={font=\footnotesize},
yticklabel style={font=\footnotesize},
colorbar,
colorbar style={%
ytick={0,0.5,1},
yticklabels={0,0.5,1},
yticklabel style={font=\footnotesize}
},
point meta min=0,
point meta max=1
]
\addplot[
matrix plot,
mesh/cols=8,
point meta=explicit
]
table[meta=C]{
x y C
0 0 0
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
0 1 0
1 1 0
2 1 0
3 1 0
4 1 0
5 1 0
6 1 0
7 1 0
0 2 0
1 2 0
2 2 0
3 2 0
4 2 0.28375
5 2 0.74154
6 2 0.93155
7 2 0.93156
0 3 0
1 3 0
2 3 0
3 3 0.53989
4 3 0.99942
5 3 1
6 3 1
7 3 1
0 4 0
1 4 0
2 4 0.28375
3 4 0.99942
4 4 1
5 4 1
6 4 1
7 4 1
0 5 0
1 5 0
2 5 0.74154
3 5 1
4 5 1
5 5 1
6 5 1
7 5 1
0 6 0
1 6 0
2 6 0.93155
3 6 1
4 6 1
5 6 1
6 6 1
7 6 1
0 7 0
1 7 0
2 7 0.93156
3 7 1
4 7 1
5 7 1
6 7 1
7 7 1
};
\draw (0,0) grid (8,8);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
只需使用内置网格。
\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{
width=8cm,
height=8cm,
compat=1.17,
colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0.15)},
xtick=\empty,
ytick=\empty
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
enlargelimits=false,
xlabel style={font=\footnotesize},
ylabel style={font=\footnotesize},
legend style={font=\footnotesize},
xticklabel style={font=\footnotesize},
yticklabel style={font=\footnotesize},
colorbar,
colorbar style={%
ytick={0,0.5,1},
yticklabels={0,0.5,1},
yticklabel style={font=\footnotesize}
},
point meta min=0,
point meta max=1,
xtick={0.5,1.5,...,7.5},ytick={0.5,1.5,...,7.5},
xticklabel=\empty,yticklabel=\empty,
grid=major
]
\addplot[
matrix plot,
mesh/cols=8,
point meta=explicit
]
table[meta=C]{
x y C
0 0 0
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
0 1 0
1 1 0
2 1 0
3 1 0
4 1 0
5 1 0
6 1 0
7 1 0
0 2 0
1 2 0
2 2 0
3 2 0
4 2 0.28375
5 2 0.74154
6 2 0.93155
7 2 0.93156
0 3 0
1 3 0
2 3 0
3 3 0.53989
4 3 0.99942
5 3 1
6 3 1
7 3 1
0 4 0
1 4 0
2 4 0.28375
3 4 0.99942
4 4 1
5 4 1
6 4 1
7 4 1
0 5 0
1 5 0
2 5 0.74154
3 5 1
4 5 1
5 5 1
6 5 1
7 5 1
0 6 0
1 6 0
2 6 0.93155
3 6 1
4 6 1
5 6 1
6 6 1
7 6 1
0 7 0
1 7 0
2 7 0.93156
3 7 1
4 7 1
5 7 1
6 7 1
7 7 1
};
\end{axis}
\end{tikzpicture}
\end{document}