我有这个矩阵图:
\documentclass[tikz]{standalone}
\usepackage{pgfplots, filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot [
matrix plot,
nodes near coords=\coordindex,mark=*,
mesh/cols=3,
point meta=explicit,
] table [meta=C] {
x y C
0 0 0
1 0 1
2 0 2
0 1 3
1 1 4
2 1 5
0 2 6
1 2 7
2 2 8
};
\end{axis}
\end{tikzpicture}
\end{document}
有没有办法nodes near coords
根据矩阵图中的字段颜色调整颜色,例如较暗的单元格有白色文本?
感谢您的帮助!
答案1
如果您只需要更改的颜色nodes near coords
,则可以使用coordinate style/.condition
如下所示的选项(但它不会影响标记):
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\addplot [
matrix plot,
nodes near coords=\coordindex,
mark=*,
mesh/cols=3,
point meta=explicit,
coordinate style/.condition={meta < 1 || meta > 7}{
white,
},
] table [meta=C] {
x y C
0 0 0
1 0 1
2 0 2
0 1 3
1 1 4
2 1 5
0 2 6
1 2 7
2 2 8
};
\end{axis}
\end{tikzpicture}
\end{document}