I want to indicate the values for the bars that are taller than the plot area in some way. Maybe by having the label inside the bar or on top of the boundaries of the plot area. Note that, I only want a label for the bars that "leave" the plot area, that is, (b, 7) and (c, 6) in this case.
I want:
What I want
I have:
What I have

I was playing around with the nodes near cords and point meta=explicit symbolic options, but no luck so far.

  symbolic x coords={a, b, c},
  % nodes near coords,
  % nodes near coords align={vertical},
  % point meta=explicit symbolic

\addplot coordinates {(a, 3)  (b, 7)[7]   (c, 1)    };
\addplot coordinates {(a, 2)  (b, 4)      (c, 6)[6] };
\addplot coordinates {(a, 4)  (b, 1)      (c, 3)    };

  • Did my answer help you to solve your problem or do you need further assistance? – Stefan Pinnow Apr 23 '17 at 22:25

This can be achieved by modifying this answer. For more details on how it works, please have a look at the comments in the code.

% used PGFPlots v1.14
        % create a variable to store the `ymax' value
        symbolic x coords={a, b, c},
        % use the previously created variable here
        % (this i just added so the outer most bars aren't clipped partially)
        enlarge x limits={0.2},
        % -----------------------------------------------------------------
        % we store the *original* y value in a variable ...
        visualization depends on={rawy \as \rawy},
        % ... which value should be shown in the `nodes near coords' ...
        nodes near coords={\pgfmathprintnumber\rawy},
        % ... and we want to limit the range of the bars to the axis limits
        restrict y to domain*={
        % ---------------------------------------------------------------------
        % now we create a style for the `nodes near coords' which is dependend
        % on the value
        % (adapted from <http://tex.stackexchange.com/a/141006/95441>)
        % (#1: the THRESHOLD after which we switch to a special display)
        nodes near coords greater equal only/.style={
            % define the style of the nodes with "small" values
            small value/.style={
            every node near coord/.append style={
                check for small values/.code={
                    % this group is merely to switch to FPU locally.
                    % Might be unnecessary, but who knows.
                    % simplifies debugging:
                        % AH: our condition 'y < #1' is met.
                        \pgfkeysalso{/pgfplots/small value}
                check for small values,
        % asign a value to the new style which is the threshold at which
        % the `small value' style is used.
        % Of course in this case it should be the `\ymax' value
        nodes near coords greater equal only=\ymax,
        % -----------------------------------------------------------------
        \addplot coordinates {(a, 3) (b, 7) (c, 1)};
        \addplot coordinates {(a, 2) (b, 4) (c, 6)};
        \addplot coordinates {(a, 4) (b, 1) (c, 3)};

image showing the result of above code

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.