![PGFPLOT 棒グラフの位置凡例と異なる表記](https://rvso.com/image/328809/PGFPLOT%20%E6%A3%92%E3%82%B0%E3%83%A9%E3%83%95%E3%81%AE%E4%BD%8D%E7%BD%AE%E5%87%A1%E4%BE%8B%E3%81%A8%E7%95%B0%E3%81%AA%E3%82%8B%E8%A1%A8%E8%A8%98.png)
棒グラフと位置凡例についてお聞きします。
\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}
ご協力ありがとうございます。2 番目の図はペイントで変更されました。
答え1
凡例の順序はプロットの順序に対応しており、 オプションで逆にすることができますreverse legend
。凡例の位置は を使用して変更できます。 、はここでは正規化された座標であるlegend style={at={(x,y)}}
ことに注意してください。以下のコードを参照してください。x
y
\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}