3

When creating a bargraph with ybar, the last added plot has a dashed outline and I don't seem to understand why.

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            axis lines=left,
            xmajorgrids,
            ymajorgrids,
            xmin=0,
            xmax=7,
            ymin=60,
            ymax=80,
            bar width=5mm
            ]
            \addplot+[ybar,mark=0,fill=black!80,draw=black]
                coordinates {
                (1,77.071)
            };
            \addplot+[ybar,mark=0,fill=black!30,draw=black]
                coordinates {
                (2,70.256)
            };
            \addplot+[ybar,mark=0,fill=black!30,draw=black]
                coordinates {
                (3,65.383)
            };
            \addplot+[ybar,mark=0,fill=black!30,draw=black]
                coordinates {
                (4,66.077)
            };
            \addplot+[ybar,mark=0,fill=black!30,draw=black]
                coordinates {
                (5,75.808)
            };
            \addplot+[ybar,mark=0,fill=black!10,draw=black]
                coordinates {
                (6,77.635)
            };
        \end{axis}
    \end{tikzpicture}
\end{document}

Output:

bargraph strange behaviour

Although, when I "add" less plots, this issue disappears, as follows:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            axis lines=left,
            xmajorgrids,
            ymajorgrids,
            xmin=0,
            xmax=7,
            ymin=60,
            ymax=80,
            bar width=5mm
            ]
            \addplot+[ybar,mark=0,fill=black!80,draw=black]
                coordinates {
                (1,77.071)
            };
            \addplot+[ybar,mark=0,fill=black!30,draw=black]
                coordinates {
                (2,70.256)(3,65.383)(4,66.077)(5,75.808)
            };
            \addplot+[ybar,mark=0,fill=black!10,draw=black]
                coordinates {
                (6,77.635)
            };
        \end{axis}
    \end{tikzpicture}
\end{document}

Output:

normal bargraph

  • 1
    If you use for the last plot \addplot+[ybar,mark=0,fill=black!10,draw=black,solid] coordinates { (6,77.635) }; it will be solid as well. I believed (without explicitly checking) that this behavior is controlled by the cycle list. – user121799 Feb 2 at 18:36
4

This behavior is controlled by the cycle list. If you look at the pgfplots manual at p. 214 you'll find

enter image description here

This explains why the 6th plot has dashed lines. One way to cure this is to add solid to the plot, or you could just create and use your own cycle list.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\pgfplotscreateplotcyclelist{Syphirint}{
   fill=black!80,draw=black,solid,mark=none\\
   fill=black!30,draw=black,solid,mark=none\\
   fill=black!30,draw=black,solid,mark=none\\
   fill=black!30,draw=black,solid,mark=none\\
   fill=black!30,draw=black,solid,mark=none\\
   fill=black!10,draw=black,solid,mark=none\\
}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[cycle list name=Syphirint,
            axis lines=left,
            xmajorgrids,
            ymajorgrids,
            xmin=0,
            xmax=7,
            ymin=60,
            ymax=80,
            bar width=5mm
            ]
            \addplot+[ybar]
                coordinates {
                (1,77.071)
            };
            \addplot+[ybar]
                coordinates {
                (2,70.256)
            };
            \addplot+[ybar]
                coordinates {
                (3,65.383)
            };
            \addplot+[ybar]
                coordinates {
                (4,66.077)
            };
            \addplot+[ybar]
                coordinates {
                (5,75.808)
            };
            \addplot+[ybar]
                coordinates {
                (6,77.635)
            };
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

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.