PGFPLOT 長條圖位置圖例與不同的符號

PGFPLOT 長條圖位置圖例與不同的符號

我想問一下有關條形圖和位置圖例的問題。

\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)}}。請注意xy這裡是標準化座標。

\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}

在此輸入影像描述

相關內容