图例中的条形图模式

图例中的条形图模式

我有一个包含三个条形图的组图,使用一个共同的图例。当我使用彩色时,这种方法效果很好,但现在我必须准备以黑白格式发布。我对 pgfplots 一点也不熟悉。

我将条形图从纯色填充改为图案,但我不知道如何制作有用的图例。任何有关如何将图案放入图例的帮助都将不胜感激。

    \documentclass{article}

    \usepackage{pgfplots}
    \usetikzlibrary{patterns}

    \begin{document}

    \begin{figure}
        \centering
        \begin{tikzpicture}
            \begin{groupplot}[
                    legend columns=-1,
                    legend entries={{\color{red}{\tiny Random}},{\color{blue}{\tiny ++Cost}},{\color{black}{\tiny ++FTE}},{\color{green}{\tiny ++Resources}},{\color{orange}{\tiny Hold All}}},
                    legend to name=CombinedLegendBar,
                    footnotesize,
                    group style={
                    group size=3 by 1,
                    xlabels at=edge bottom,
                    ylabels at=edge left,
                    xticklabels at=edge bottom}]
                \nextgroupplot[title={\scriptsize Empirical CDF}, xticklabels=\empty]
                    \addplot[ybar, pattern=horizontal lines] coordinates {  (1, 6.886)};
                    \addplot[ybar, pattern=vertical lines] coordinates { (2, 8.501)};
                    \addplot[ybar, pattern=grid] coordinates {  (3, 10.179)};
                    \addplot[ybar, pattern=dots] coordinates {  (4, 11.14)};
                    \addplot[ybar, pattern=north east lines] coordinates {  (5, 15.001)};

                \nextgroupplot[title={\scriptsize Triangular CDF}, xticklabels=\empty]
                    \addplot[ybar, pattern=horizontal lines] coordinates {(1, 6.886)};
                    \addplot[ybar, pattern=vertical lines] coordinates {(2, 7.745)};
                    \addplot[ybar, pattern=grid] coordinates {(3, 8.606)};
                    \addplot[ybar, pattern=dots] coordinates {(4, 8.630)};
                    \addplot[ybar, pattern=north east lines] coordinates {(5, 15.001)};

                \nextgroupplot[title={\scriptsize LN/Exponential CDF}, xticklabels=\empty]
                    \addplot[ybar, pattern=horizontal lines] coordinates {  (1, 6.886)};
                    \addplot[ybar, pattern=vertical lines] coordinates {    (2, 8.428)};
                    \addplot[ybar, pattern=grid] coordinates {  (3, 9.964)};
                    \addplot[ybar, pattern=dots] coordinates {  (4, 11.087)};
                    \addplot[ybar, pattern=north east lines] coordinates {  (5, 15.001)};

            \end{groupplot}
        \end{tikzpicture}
        \ref{CombinedLegendBar}
        \caption{Triage++ Performance}
        \label{PlusPlusCombinedBar}
    \end{figure}
\end{document}

在此处输入图片描述

答案1

ybar legend您可以将v1.12 手册第 211 页中说明的选项添加到轴选项中。您还可以使用area legend轴选项中的选项,该选项在手册的同一页中说明。请注意,我必须加载库并在 MWE 中groupplots设置兼容性。compat=1.12

\documentclass{article}

    \usepackage{pgfplots}
    \usepgfplotslibrary{groupplots}
    \pgfplotsset{compat=1.12}
    \usetikzlibrary{patterns}

    \begin{document}

    \begin{figure}
        \centering
        \begin{tikzpicture}
            \begin{groupplot}[
                    legend columns=-1,
                    legend entries={{\color{red}{\tiny Random}},{\color{blue}{\tiny ++Cost}},{\color{black}{\tiny ++FTE}},{\color{green}{\tiny ++Resources}},{\color{orange}{\tiny Hold All}}},
                    legend to name=CombinedLegendBar,
                    footnotesize,
                    ybar legend,
                    % area legend, % This is the alternate option
                    group style={
                    group size=3 by 1,
                    xlabels at=edge bottom,
                    ylabels at=edge left,
                    xticklabels at=edge bottom}]
                \nextgroupplot[title={\scriptsize Empirical CDF}, xticklabels=\empty]
                    \addplot[ybar, pattern=horizontal lines] coordinates {  (1, 6.886)};
                    \addplot[ybar, pattern=vertical lines] coordinates { (2, 8.501)};
                    \addplot[ybar, pattern=grid] coordinates {  (3, 10.179)};
                    \addplot[ybar, pattern=dots] coordinates {  (4, 11.14)};
                    \addplot[ybar, pattern=north east lines] coordinates {  (5, 15.001)};

                \nextgroupplot[title={\scriptsize Triangular CDF}, xticklabels=\empty]
                    \addplot[ybar, pattern=horizontal lines] coordinates {(1, 6.886)};
                    \addplot[ybar, pattern=vertical lines] coordinates {(2, 7.745)};
                    \addplot[ybar, pattern=grid] coordinates {(3, 8.606)};
                    \addplot[ybar, pattern=dots] coordinates {(4, 8.630)};
                    \addplot[ybar, pattern=north east lines] coordinates {(5, 15.001)};

                \nextgroupplot[title={\scriptsize LN/Exponential CDF}, xticklabels=\empty]
                    \addplot[ybar, pattern=horizontal lines] coordinates {  (1, 6.886)};
                    \addplot[ybar, pattern=vertical lines] coordinates {    (2, 8.428)};
                    \addplot[ybar, pattern=grid] coordinates {  (3, 9.964)};
                    \addplot[ybar, pattern=dots] coordinates {  (4, 11.087)};
                    \addplot[ybar, pattern=north east lines] coordinates {  (5, 15.001)};

            \end{groupplot}
        \end{tikzpicture}
        \ref{CombinedLegendBar}
        \caption{Triage++ Performance}
        \label{PlusPlusCombinedBar}
    \end{figure}
\end{document}

ybar legend在此处输入图片描述

area legend在此处输入图片描述

相关内容