![Legenda da posição do gráfico de barras PGFPLOT e notação diferente](https://rvso.com/image/328809/Legenda%20da%20posi%C3%A7%C3%A3o%20do%20gr%C3%A1fico%20de%20barras%20PGFPLOT%20e%20nota%C3%A7%C3%A3o%20diferente.png)
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}
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 legend
opção. A posição da legenda pode ser modificada através de legend style={at={(x,y)}}
. Observe que x
aqui y
estã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}