[Tex/LaTex] Nodes Near coords hide when 0

nodes-near-coordspgfplots

Is it possible to hide nodes near coords in pgfplots when value = 0 ?

I have something like this.

enter image description here

And axis setting

\begin{axis}[
  ybar,
  bar width=3pt,
  nodes near coords
]

Best Answer

As standard node near coordinates is \pgfmathprintnumber{\pgfplotspointmeta}. You want to run that only if \pgfplotspointmeta is non-zero. This may be tested for with \pgfmathfloatifflags as follows:

near coords={\pgfmathfloatifflags{\pgfplotspointmeta}{0}{}{\pgfmathprintnumber{\pgfplotspointmeta}}}

with 0 indicating test whether the number is equal to zero, {} being the action if it is and the final group containing the action if it is not zero.

You don't provide the code for your plot, so here is a similar case instead:

Sample output

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    ybar,
    bar width=3pt,
    nodes near coords={\pgfmathfloatifflags{\pgfplotspointmeta}{0}{}{\pgfmathprintnumber{\pgfplotspointmeta}}}
    ]
    \addplot coordinates
    {(0,3) (1,0) (2,0) (3,1) (4,2)};
  \end{axis}
\end{tikzpicture}

\end{document}