Legenda da posição do gráfico de barras PGFPLOT e notação diferente

Legenda da posição do gráfico de barras PGFPLOT e notação diferente

Gostaria de perguntar sobre o gráfico de barras e a legenda da posição.

\usepackage{pgfplots}
    \begin{document}
    \begin{tikzpicture}
      \begin{axis}
        [ xbar,
        %enlargelimits=0.14,width=8cm,height=6cm,,
            bar width=10pt,area legend,legend pos=south east,
            legend style={cells={anchor=west}}, area legend,
            tick align=outside,xlabel=\textbf{EUR Billion},
            ytick={1,...,3},
            yticklabel style={text width=3.3cm,align=right},
            yticklabels={Automotive \& Aircraft,
                                        Building Sector,ICT}]

      \addplot[draw=blue,fill=blue!15]
                        coordinates {(42,1) (34.5,2) (42,3)};

        \addlegendentry{\textsc{2016}}

        \addplot[draw=blue,fill=blue!50]
                        coordinates {(16.5,1) (15,2) (11.25,3)};


        \addlegendentry{\textsc{2006}}
    \end{axis}
    \end{tikzpicture}

Eu tenho isto: eu tenho este

Mas eu quero o seguinte: Eu quero este

Agradecemos antecipadamente pelo seu tempo e ajuda. A segunda figura foi alterada no Paint.

Responder1

A ordenação da legenda corresponde à ordenação das parcelas, podendo ser invertida pela reverse legendopção. A posição da legenda pode ser modificada através de legend style={at={(x,y)}}. Observe que xaqui yestão coordenadas normalizadas. Veja o código abaixo.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}
        [ xbar,
            bar width=10pt,area legend,legend pos=south east,
            reverse legend,
            legend style={cells={anchor=west},at={(0.99,0.42)}}, area legend,
            tick align=outside,xlabel=\textbf{EUR Billion},
            ytick={1,...,3},
            yticklabel style={text width=3.3cm,align=right},
            yticklabels={Automotive \& Aircraft,
                                        Building Sector,ICT}]

        \addplot[draw=blue,fill=blue!15]
            coordinates {(42,1) (34.5,2) (42,3)};
        \addlegendentry{\textsc{2016}}                            

        \addplot[draw=blue,fill=blue!50]
            coordinates {(16.5,1) (15,2) (11.25,3)};
        \addlegendentry{\textsc{2006}}

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

insira a descrição da imagem aqui

informação relacionada