Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm plotting bar plot using this code:

\documentclass[tikz,12pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usetikzlibrary{arrows,decorations.pathmorphing,shadows,calc,intersections}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{xcolor}
\pgfplotsset{width=12cm,compat=1.9}
\tikzset{
%Define standard arrow tip
>=stealth'
}
\begin{document}
\pgfplotsset{every axis/.append style={
font=\normalsize\rmfamily,
line width=1 pt,
tick style={line width=.6pt}}}
\begin{tikzpicture}
  \begin{axis}[
    axis background/.style={shade,top color=gray,bottom color=white},
    height=8cm,
    ybar,
    ymin=0,
    bar width=1.2cm,
    minor y tick num=4,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.2)},
      anchor=north,legend columns=-1},
    ylabel={Count},
    symbolic x coords={5--10 years,10--15 years, 15--20 years,20--25 years,Over 25 years},
        xtick=data,
        nodes near coords, 
        nodes near coords align={vertical},
        x tick label style={font=\normalsize,text width=1.5cm,align=center},
        ]    \addplot[fill=green!25!gray] coordinates {(5--10 years,32) (10--15 years,12) (15--20 years,3) (20--25 years,2) (Over 25 years,3)};

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

enter image description here

I want to have y minimum equal to 0. I have set:

...
ymin=0,
...

But as you can see, it does not work.

Please help to solve this problem.

And secondly. How to put values inside of the bar?

Thank you in advance.

share|improve this question
3  
Remove the enlargelimits=0.15 if you don't want to enlarge the limits of the axis past the specified ymin value. To put the nodes inside the bars, use every node near coord/.append style={anchor=north}. –  Jake Jan 30 at 18:14
    
Thank you! It works. But why enlargelimits=0.15 make such effect? –  saldenisov Jan 30 at 19:14
    
@saldenisov: Because that's what enlargelimits is designed to do. From the pgfplots manual: "Axis limits can be increased automatically using the enlargelimits option." –  Paul Gessler Jan 30 at 19:31
    
But if I need to use enlargelimits t effect x axis? What than should I do?Thank you. –  saldenisov Jan 30 at 19:37

1 Answer 1

up vote 4 down vote accepted

pgfplots, by default, uses enlargelimits=0.15 in all directions.
You can change this to enlarge x limits=0.15 to only enlarge the limits in x direction, which then looks like this:

enlarge x limits=0.15

where nodes near coords manages to expand the y axis enough to include the nodes, but enlarge x limits=0.15,enlarge y limits={value=0.15,upper}, gives the more equally spaced lower picture.

enlarge x limits=0.15,enlarge y limits={value=0.15,upper}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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