3

When I use both "bar width" and "symbolic x", pdflatex gives me the following error message:

! Package pgfkeys Error: I do not know the key '/pgfplots/bar width' and I am going to ignore it. Perhaps you misspelled it.

Do you have any idea how I can choose the bar size with "symbolic x" option ?

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\pgfplotsset{
    compat=newest,
    ybar stacked,
    symbolic x coords={val1,val2,val3},
    %bar width=1,% doest not work
}

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot[black!40,pattern=north west lines, pattern color=blue] coordinates
{(val1,36.8539)  (val2,33.7547)      (val3,13.7547)};
        \addplot[black!40,pattern=north west lines, pattern color=red]  coordinates
{(val1,13.47)    (val2,12.7187)          (val3,22.7187)};
    \end{axis}
\end{tikzpicture}
\end{document}
5

You are inside pgfplotsset which sets pgfplots keys. Bar width is a PGF key. You can supply the options to the axis in which the keys are also tried PGF key family if it can't find it inside the pgfplots family.

If you want to use these options more than once you can save it in a style and provide to every axis or alternatively you can set it via \pgfkeys{/pgf/bar width=2cm}. Or you can create an alias for this key. Interesting that this is a PGF key indeed.

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[ybar stacked,symbolic x coords={val1,val2,val3},bar width=1cm,xtick=data,enlarge x limits={abs=1.5cm}]
        \addplot[black!40,pattern=north west lines, pattern color=blue] coordinates
{(val1,36.8539)(val2,33.7547)(val3,13.7547)};
        \addplot[black!40,pattern=north west lines, pattern color=red]  coordinates
{(val1,13.47)(val2,12.7187)(val3,22.7187)};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||

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.