1

I have a matrix plot with nan meta values. Now I want to print only the nodes near coords which are not nan but somehow I cannot figure out how to do that.

Here is a MWE:

\documentclass[tikz, border=1cm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{ifthen}
\pgfplotsset{width=7cm,compat=1.18}

\begin{document} \begin{tikzpicture} \begin{axis}[enlargelimits=false, point meta rel=per plot, nodes near coords={% \ifthenelse{\expandafter\equal{\pgfmathprintnumber\pgfplotspointmeta}{NaN}}{}{\pgfmathprintnumber\pgfplotspointmeta}}] \addplot [matrix plot, point meta=explicit, ] coordinates { (0,0) [0] (1,0) [1] (2,0) [2]

(0,1) [nan] (1,1) [nan] (2,1) [nan]

}; \end{axis} \end{tikzpicture} \end{document}

Thanks for any help!

1 Answers1

1

Expanding on this great answer, you could text against the flag of the relevant value:

\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm, compat=1.18}

\begin{document} \begin{tikzpicture} \begin{axis}[ enlargelimits=false, point meta rel=per plot, nodes near coords={% \pgfmathfloatparsenumber{\pgfplotspointmeta} \pgfmathfloatgetflagstomacro\pgfmathresult\currentflags \ifnum\currentflags=3\else \pgfmathprintnumber\pgfplotspointmeta \fi } ] \addplot[ matrix plot, point meta=explicit, ] coordinates { (0,0) [0] (1,0) [1] (2,0) [2]

(0,1) [nan] (1,1) [nan] (2,1) [nan]

}; \end{axis} \end{tikzpicture} \end{document}

enter image description here