Hiding 0 values from nodes within a bar graph

nodes-near-coordspgfplotstikz-pgf

Is it possible to hide the 0 values from appearing when I have node near coords active? even better if I could hide the bar graphs for those specific 0 values.

I tried using nodes near coords=y filter/.expression={y==0 ? nan : y}, however, it hid the x axis labels.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\pgfplotsset{width=7cm,compat=1.3}
\hyphenation{}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    legend style={font=\tiny},
    ybar=1pt,
    bar width =2pt,
    ymin=0,ymax=200,
    enlarge y limits={upper=0.15},
    legend image code/.code={\draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.3cm,0.1cm);
                },
    ymajorgrids = true,
    legend style={at={(-0.00000009,0.845)},
                   anchor=west,legend columns=1},
    ylabel={Energy Consumption (Watts)},
    symbolic x coords={R2G,Gaussian,Box,Sobel,Gsn Pyd,Extrema,Orientation,Descriptor,Edge Total,SIFT Total},
    xtick=data,
    nodes near coords,
    nodes near coords style={font=\tiny, anchor=west,rotate=90,inner
    xsep=0.5pt},
    x tick label style = {font=\small, rotate=45, anchor=east},
    ]

\addplot coordinates {(R2G,54) (Gaussian,68)  (Box,80) (Sobel,95) (Gsn Pyd,0)(Extrema,0) (Orientation,0) (Descriptor,0) (Edge Total, 105)  (SIFT Total, 125)};%CPU

\addplot [fill=teal!]  coordinates {(R2G,80) (Gaussian,105)  (Box,111) (Sobel,120) (Gsn Pyd,130)(Extrema,50) (Orientation,47) (Descriptor,35) (Edge Total, 132) (SIFT Total, 150)  };%GPU

\addplot coordinates {(R2G,11) (Gaussian,32)  (Box,32) (Sobel,20) (Gsn Pyd,26)(Extrema,12) (Orientation,10) (Descriptor,5) (Edge Total, 43) (SIFT Total, 52) };%FPGA

\addplot coordinates {(R2G,15) (Gaussian,38)  (Box,39) (Sobel,32) (Gsn Pyd,28) (Extrema,18) (Orientation,15) (Descriptor,9) (Edge Total, 52) (SIFT Total, 72) };%HLS

\legend{CPU,GPU,FPGA,HLS}
\end{axis}
\end{tikzpicture}
\end{document}

Best Answer

Using y filter/.expression={y==0 ? nan : y} I would suggest something like this: Just move the GPU plot in front of the CPU plot and the labels remain.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\pgfplotsset{width=7cm,compat=1.3}
\hyphenation{}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    legend style={font=\tiny},
    ybar=1pt,
    bar width =2pt,
    ymin=0,ymax=200,
    y filter/.expression={y==0 ? nan : y},
    enlarge y limits={upper=0.15},
    legend image code/.code={\draw[#1, draw=none] (0cm,-0.1cm) rectangle (0.3cm,0.1cm);
                },
    ymajorgrids = true,
    legend style={at={(-0.00000009,0.845)},
                   anchor=west,legend columns=1},
    ylabel={Energy Consumption (Watts)},
    symbolic x coords={R2G,Gaussian,Box,Sobel,Gsn Pyd,Extrema,Orientation,Descriptor,Edge Total,SIFT Total},
    xtick=data,
    nodes near coords,
    nodes near coords style={font=\tiny, anchor=west,rotate=90,inner
    xsep=0.5pt},
    x tick label style = {font=\small, rotate=45, anchor=east},
    ]
\addplot [fill=teal!] coordinates {(R2G,80) (Gaussian,105)  (Box,111) (Sobel,120) (Gsn Pyd,130)(Extrema,50) (Orientation,47) (Descriptor,35) (Edge Total, 132) (SIFT Total, 150)  };%GPU

\addplot coordinates {(R2G,54) (Gaussian,68)  (Box,80) (Sobel,95) (Gsn Pyd,0)(Extrema,0) (Orientation,0) (Descriptor,0) (Edge Total, 105)  (SIFT Total, 125)};%CPU

\addplot coordinates {(R2G,11) (Gaussian,32)  (Box,32) (Sobel,20) (Gsn Pyd,26)(Extrema,12) (Orientation,10) (Descriptor,5) (Edge Total, 43) (SIFT Total, 52) };%FPGA

\addplot coordinates {(R2G,15) (Gaussian,38)  (Box,39) (Sobel,32) (Gsn Pyd,28) (Extrema,18) (Orientation,15) (Descriptor,9) (Edge Total, 52) (SIFT Total, 72) };%HLS

\legend{GPU,CPU,FPGA,HLS}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Related Question