3

I'm having trouble with pgfplots using ybar. When I try:

\begin{tikzpicture}
\begin{axis}[height=4.5cm, width=8cm, ybar, axis x line=bottom, axis y line=left, grid=none, ytick={0,10,20}, xmin=0, xmax=7, xtick={1,...,6}, x axis line style=-]
\addplot+[ybar] plot coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,14)};
\end{axis}
\end{tikzpicture}

I get this:

enter image description here

Which isn't what I wanted, since 4 should have a height of 13.

Trying this:

\begin{tikzpicture}
\begin{axis}[height=4.5cm, width=8cm, ybar, axis x line=bottom, axis y line=left, grid=none, ytick={0,10,20}, xmin=0, xmax=7, xtick={1,...,6}, x axis line style=-]
\addplot+[ybar] plot coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,0)};
\end{axis}
\end{tikzpicture}

Gives this:

enter image description here

Am I doing something wrong? How come I can't get the bars to be the correct heights?

  • The backtick is for inline code, you can indent lines with four whitespace characters to mark as a block code. Also your plot is correct. 4 has the ymin value of 13. try decreasing ymin value – percusse Feb 26 '14 at 0:37
  • removing ` axis y line=left,` seems to fix it – cmhughes Feb 26 '14 at 0:57
  • Seems like a bug? I can reproduce the undesired behaviour using \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document} \begin{tikzpicture} \begin{axis}[ybar] \addplot+ plot coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,14)}; \end{axis} \end{tikzpicture} \end{document} – Gonzalo Medina Feb 26 '14 at 3:17
2

If you include the ymin en ymax it works. Don't know why though.

\begin{tikzpicture}
    \begin{axis}[height=4.5cm, width=8cm, ybar, axis x line=bottom, axis y line=left, grid=none, ytick={0,10,20}, ymin=0, ymax=25, xmin=0, xmax=7, xtick={1,...,6}, x axis line style=-]
        \addplot+[ybar] coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,14)};
    \end{axis}
\end{tikzpicture}

enter image description here

  • 2
    This is the answer. In fact, ymin=0 would be sufficient... in the original post, pgfplots computed the lower axis limit to be 13. – Christian Feuersänger Feb 26 '14 at 20:06
1

Another alternative this solution found is to use axis y line*=left instead of axis y line=left since the latter modifies the y label style. Please see this link ylabel style when axis y line=right

enter image description here

Code

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
%\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[height=4.5cm, width=8cm, ybar, axis x line=bottom, axis y line*=left,grid=none, ytick={0,10,20}, xmin=0, xmax=7, xtick={1,...,6}, x axis line style=-]
\addplot+[ybar] plot coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,14)};
\end{axis}
\end{tikzpicture}

x axis line = none

\begin{tikzpicture}
\begin{axis}[height=4.5cm, width=8cm, ybar, axis x line=none, axis y line*=left,grid=none, ytick={0,10,20}, xmin=0, xmax=7, xtick={1,...,6}, x axis line style=-]
\addplot+[ybar] plot coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,0)};
\end{axis}
\end{tikzpicture}

x axis line = top

\begin{tikzpicture}
\begin{axis}[height=4.5cm, width=8cm, ybar, axis x line=top, axis y line*=left,grid=none, ytick={0,10,20}, xmin=0, xmax=7, xtick={1,...,6}, x axis line style=-]
\addplot+[ybar] plot coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,0)};
\end{axis}
\end{tikzpicture}

x axis line = bottom

\begin{tikzpicture}
\begin{axis}[height=4.5cm, width=8cm, ybar, axis x line=bottom, axis y line*=left,grid=none, ytick={0,10,20}, xmin=0, xmax=7, xtick={1,...,6}, x axis line style=-]
\addplot+[ybar] plot coordinates {(1,16) (2,18) (3,23) (4,13) (5,16) (6,0)};
\end{axis}
\end{tikzpicture}


\end{document}

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.