1
\documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}
\usepackage{xcolor, color}


\begin{document}

\begin{tikzpicture}
    \definecolor{SpecialYellow}{HTML}{F9DC21}
    \definecolor{SpecialGreen}{HTML}{46A62E}
    \definecolor{SpecialBlue}{HTML}{4192F5}

    \pgfplotstableread{
    Label   Engine  Check   OS
    Cached  4.49    0.83    4
    Normal  12.45   3.9     12
    }\datatable

    \begin{axis}[xbar stacked, xmin=0, xmax=30, ytick=data, yticklabels from table={\datatable}{Label}, draw=black, height=25mm, width=5cm, legend style={at={(0,1.5)}, anchor=west,legend columns=3, area legend} ]
        \addlegendentry{Engine}
        \addplot [fill=SpecialBlue, draw=none] table[x=Engine] {\datatable};
        \addlegendentry{Check}
        \addplot [fill=SpecialGreen, draw=white] table[x=Check] {\datatable};
        \addlegendentry{OS}
        \addplot [fill=SpecialYellow, draw=white] table[x=OS] {\datatable};
    \end{axis}
\end{tikzpicture}
\end{document}
1

[area legend] needs to be outside the [legend style].

I couldn't figure out what the y coordinates were for this plot. 0 corresponds to below the bottom. The center of the lower bar is at about 5 and the upper bar at about 12.

\documentclass[border=5mm] {standalone}
\usepackage{pgfplots, pgfplotstable}
\usepackage{xcolor, color}

\begin{document}

\pgfplotstableread{
  Label   Engine  Check   OS
  Cached  4.49    0.83    4
  Normal  12.45   3.9     12
}\datatable

\begin{tikzpicture}
    \definecolor{SpecialYellow}{HTML}{F9DC21}
    \definecolor{SpecialGreen}{HTML}{46A62E}
    \definecolor{SpecialBlue}{HTML}{4192F5}

    \begin{axis}[xbar stacked, xmin=0, xmax=30, ytick=data, yticklabels from table={\datatable}{Label}, 
      draw=black, height=25mm, width=5cm, tick align=outside,
      legend style={at={(0,1.5)}, anchor=west,legend columns=3}, area legend]
        \addlegendentry{Engine}
        \addplot [fill=SpecialBlue, draw=none] table[x=Engine] {\datatable};
        \addlegendentry{Check}
        \addplot [fill=SpecialGreen, draw=white] table[x=Check] {\datatable};
        \addlegendentry{OS}
        \addplot [fill=SpecialYellow, draw=white] table[x=OS] {\datatable};
        \coordinate (A) at (axis cs: 4.49,5);
    \end{axis}
    \node[inner sep=0pt,left] at (A) {\scriptsize 4.49};
\end{tikzpicture}
\end{document}

bar plot

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.