![PGFPLOT 長條圖位置圖例與不同的符號](https://rvso.com/image/328809/PGFPLOT%20%E9%95%B7%E6%A2%9D%E5%9C%96%E4%BD%8D%E7%BD%AE%E5%9C%96%E4%BE%8B%E8%88%87%E4%B8%8D%E5%90%8C%E7%9A%84%E7%AC%A6%E8%99%9F.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}
預先感謝您的時間和幫助。第二個數字在畫圖中發生了變化。
答案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}