Pgfplot 图例类型

Pgfplot 图例类型

我需要下面给出的图例类型。我只想写入一次参数值。我怎样才能获得这种类型的图例。

代码示例

\documentclass{article}
    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usepackage{amssymb}
    \usepackage{color}
    \begin{document}
        \begin{center}
            $\begin{array}{lcl}
            & \mu & \sigma^2\\
            \hline {\color{blue}{\noindent\rule{1.5cm}{0.4pt}}} & 0 & 1\\
            {\color{red}\noindent\rule{1.5cm}{0.4pt}} & 1 & 1\\
            {\color{green}\noindent\rule{1.5cm}{0.4pt}} & 2 & 1\\
            {\color{yellow}\noindent\rule{1.5cm}{0.4pt}} & 3 & 2
            \end{array}$
    \par\end{center}
    \end{document}

在此处输入图片描述

答案1

这是最多去那里的路:

截屏

它大量借鉴了我的回答如何在 pgfplots 上自定义图例?以及其中的链接。

唯一缺少的是水平线;如果有人可以在我的答案的基础上实现它,我会很乐意删除它。

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}

% https://tex.stackexchange.com/questions/84127/correctly-align-vertical-text-on-a-baseline-in-pgfplots
\def\mystrut{\vphantom{hg}}


\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            legend columns=2,
            legend style={
                font=\mystrut,
                legend cell align=left,
            },
            legend pos=south east,
        ]
        % column 1 heading
        \addlegendimage{empty legend}
        \addlegendentry{$\mu$}
        % column 2 heading
        \addlegendimage{empty legend}
        \addlegendentry{$\sigma^2$}
        % row 1, column 1
        \addplot {x+4};
        \addlegendentry{0}
        % row 1, column 2
        \addlegendimage{empty legend}
        \addlegendentry{1}
        % row 2, column 1
        \addplot {2*x+4};
        \addlegendentry{1}
        % row 2, column 2
        \addlegendimage{empty legend}
        \addlegendentry{1}
        % row 3, column 1
        \addplot {4*x+4};
        \addlegendentry{2}
        % row 3, column 2
        \addlegendimage{empty legend}
        \addlegendentry{1}
        % row 4, column 1
        \addplot {3*x+3};
        \addlegendentry{3}
        % row 4, column 2
        \addlegendimage{empty legend}
        \addlegendentry{2}
    \end{axis}
\end{tikzpicture}

\end{document}

相关内容