4

I'm trying to only have the y-value exceeding the axis to be labelled and not the rest (as shown in the picture below). Is there any suggestion how this can be made?enter image description here

my MWE (thanks to @Jake):

    \documentclass{scrbook}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.pathmorphing}


\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
        width  = 0.9*\textwidth,
        height = 8cm,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=4pt,
        ymin=0,
        axis on top,
        ymax=12,
        ymajorgrids = true,
        xtick = data,
        xlabel = {Environmental indicators},
        symbolic x coords={GWP, ODP, POCP, AP, EP(T), EP(FW), EP(M), ADP, CED},
        restrict y to domain*=0:14, % Cut values off at 14
    visualization depends on=rawy\as\rawy, % Save the unclipped values
    after end axis/.code={ % Draw line indicating break
     \draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,1.05) -- (rel axis cs:1,1.05);
        },
    nodes near coords={%
     \pgfmathprintnumber{\rawy}% Print unclipped values
        },
    axis lines*=left,
    clip=false
    ]
\addplot[style={bblue,fill=bblue,mark=none}]
            coordinates {   (GWP, 1.0) 
                            (ODP,1.0)
                            (POCP,1.0)
                            (AP,1.0)
                            (EP(T),1.0)
                            (EP(FW),1.0)
                            (EP(M),1.0)
                            (ADP,1.0)
                            (CED,1.0)};
        \addplot[style={rred,fill=rred,mark=none}]
             coordinates {(GWP,0.11) 
                            (ODP,4.28) 
                            (POCP,0.28 )
                            (AP,0.67)
                            (EP(T),0.38)
                            (EP(FW),1.0)
                            (EP(M),0.55)
                            (ADP,4.20)
                            (CED,1.0)};
        \addplot[style={ggreen,fill=ggreen,mark=none}]
             coordinates {(GWP,1.42)
                            (ODP,1.37) 
                            (POCP,1.26)
                            (AP,6.50)
                            (EP(T),6.65)
                            (EP(FW),48.56)
                            (EP(M),2.97)
                            (ADP,2.25)
                            (CED,1.0)};
\addplot[style={ppurple,fill=ppurple,mark=none}]
             coordinates {  (GWP,0.74) 
                            (ODP,2.07) 
                            (POCP,2.69)
                            (AP,7.10)
                            (EP(T),3.03)
                            (EP(FW),6.88)
                            (EP(M),3.04)
                            (ADP,2.53)
                            (CED,1.0)};
\legend{Singapore,France,Germany,Spain}
    \end{axis}
\end{tikzpicture}
\caption{Comparison of electricity profiles per 1 kWh of electricity}
\end{figure}
\end{document}
2
2

Two steps to get this. The first is that you need to remove nodes near coords and its value from the \begin[axis] parameter list. (This removes all labels). Next, you need to add nodes near coords into the individual \addplot with the green bars. Doing this, you are stuck with all the green bars having a title, which is obviously not exactly what you need.

However, there is a trick to only added nodes near coords value on the particular coordinate that you want. (You count coordinates starting from an index of 0). So, in this case, (EP(FW),48.56) is the sixth item but index 5. Take the value {\pgfmathprintnumber{\rawy}} from above and wrap it with \ifnum...\fi as this example shows:

\documentclass{scrbook}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.pathmorphing}


\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
        width  = 0.9*\textwidth,
        height = 8cm,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=4pt,
        ymin=0,
        axis on top,
        ymax=12,
        ymajorgrids = true,
        xtick = data,
        xlabel = {Environmental indicators},
        symbolic x coords={GWP, ODP, POCP, AP, EP(T), EP(FW), EP(M), ADP, CED},
        restrict y to domain*=0:14, % Cut values off at 14
    visualization depends on=rawy\as\rawy, % Save the unclipped values
    after end axis/.code={ % Draw line indicating break
     \draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,1.05) -- (rel axis cs:1,1.05);
        },
    %nodes near coords={%
     %\pgfmathprintnumber{\rawy}% Print unclipped values
     %},%REMOVED THIS PART
    axis lines*=left,
    clip=false
    ]
\addplot[style={bblue,fill=bblue,mark=none}]
            coordinates {(GWP, 1.0) 
                            (ODP,1.0)
                            (POCP,1.0)
                            (AP,1.0)
                            (EP(T),1.0)
                            (EP(FW),1.0)
                            (EP(M),1.0)
                            (ADP,1.0)
                            (CED,1.0)};
        \addplot[style={rred,fill=rred,mark=none}]
             coordinates {(GWP,0.11) 
                            (ODP,4.28) 
                            (POCP,0.28 )
                            (AP,0.67)
                            (EP(T),0.38)
                            (EP(FW),1.0)
                            (EP(M),0.55)
                            (ADP,4.20)
                            (CED,1.0)};
        \addplot[style={ggreen,fill=ggreen,mark=none},nodes near coords={\ifnum\coordindex=5{\pgfmathprintnumber{\rawy}}\else\fi}]%UPDATED THIS WITH A CONDITIONAL
             coordinates {(GWP,1.42)
                            (ODP,1.37) 
                            (POCP,1.26)
                            (AP,6.50)
                            (EP(T),6.65)
                            (EP(FW),48.56)
                            (EP(M),2.97)
                            (ADP,2.25)
                            (CED,1.0)};
        \addplot[style={ppurple,fill=ppurple,mark=none}]
             coordinates {  (GWP,0.74) 
                            (ODP,2.07) 
                            (POCP,2.69)
                            (AP,7.10)
                            (EP(T),3.03)
                            (EP(FW),6.88)
                            (EP(M),3.04)
                            (ADP,2.53)
                            (CED,1.0)};
\legend{Singapore,France,Germany,Spain}
    \end{axis}
\end{tikzpicture}
\caption{Comparison of electricity profiles per 1 kWh of electricity}
\end{figure}
\end{document}

Graph with only one bar having a label

EDIT:

In case you are interested, I was able to adapt this from a somewhat similar question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.