pgfplots,每个组图都有不同的图例

pgfplots,每个组图都有不同的图例

我正在尝试在每个组图下方放置不同的图例。我使用以下代码:

\begin{tikzpicture}
\begin{groupplot}[
    group style={
        group name=my plots,
        group size=2 by 1,
        xlabels at=edge bottom,
        ylabels at=edge left,
        horizontal sep=2cm,vertical sep=3cm,},
    xlabel={ Radius },
    x tick label style={
        /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=2,
        /tikz/.cd
    },
    ylabel={ Recall },
    y tick label style={
        /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=1,
        /tikz/.cd
    },
    ymin=0,
    ymax=1
    ]
    \nextgroupplot[
    title={n=1e4},
    legend style={at={($(0,0)+(1cm,1cm)$)},legend columns=3,fill=none,draw=none,anchor=center,align=center},
    legend to name=first
    ]
    \addplot coordinates {
        (0.01, 0.194)
        (0.02, 0.6191)
        (0.03, 0.7416)
        (0.04, 0.6602)
        (0.05, 0.5226)
        (0.06, 0.4083)
        (0.08, 0.242)
    };
    \addlegendentry{ d=3 };
    \addplot coordinates {
        (0.05, 0.275)
        (0.07, 0.5703)
        (0.10, 0.5977)
        (0.11, 0.5193)
        (0.13, 0.345)
        (0.15, 0.2077)
    };
    \addlegendentry{  d=6 };
    \addplot coordinates {
        (0.08, 0.3073)
        (0.10, 0.5765)
        (0.12, 0.6504)
        (0.14, 0.5119)
        (0.16, 0.3224)
        (0.18, 0.1974)
    };
    \addlegendentry{  d=9 };
    \addplot coordinates {
        (0.10, 0.351)
        (0.12, 0.6850)
        (0.14, 0.7099)
        (0.16, 0.4944)
        (0.18, 0.2779)
    };
    \addlegendentry{  d=12 };
    \addplot coordinates {
        (0.12, 0.1489)
        (0.14, 0.3979)
        (0.16, 0.6301)
        (0.18, 0.6441)
        (0.20, 0.4828)
        (0.22, 0.2951)
    };
    \addlegendentry{  d=15 };
    \coordinate (c1) at (rel axis cs:0,1);
    \coordinate (c2) at (rel axis cs:1,1);
    \nextgroupplot[
    title={3D},
    legend style={at={($(0,0)+(1cm,1cm)$)},legend columns=3,fill=none,draw=none,anchor=center,align=center},
    legend to name=second
    ]
    \coordinate (c4) at (rel axis cs:0,1);
    \coordinate (c5) at (rel axis cs:1,1);
    \coordinate (c6) at ($(c4)!.5!(c5)$);
    \addplot coordinates {
        (0.02, 0.192)
        (0.04, 0.67)
        (0.06, 0.8909)
        (0.08, 0.8624)
        (0.10, 0.7026)
        (0.12, 0.5396)
        (0.14, 0.4168)
    \addlegendentry{  n=1e3 };
    };
    \addplot coordinates {
        (0.01, 0.194)
        (0.02, 0.6191)
        (0.03, 0.7416)
        (0.04, 0.6602)
        (0.05, 0.5226)
        (0.06, 0.4083)
        (0.08, 0.242)
    };
    \addlegendentry{  n=1e4 };
    \addplot coordinates {
        (0.008, 0.445)
        (0.01, 0.5644)
        (0.014, 0.6451)
        (0.02, 0.5823)
        (0.04, 0.2981) 
    };
    \addlegendentry{  n=1e5 };
\end{groupplot}
\coordinate (c3) at ($(c1)!.5!(c2)$);
\node[below] at (c3 |- current bounding box.south)
{\pgfplotslegendfromname{first}};
\node[below] at (c6 |- current bounding box.south)
{\pgfplotslegendfromname{second}};
\end{tikzpicture}

但是,它就是编译不出来,没有错误,它只是不断地编译。我做错了什么?从第二个图中删除图例,让它编译,但我需要图例。

答案1

您错误地在坐标流中添加了图例条目。

\addplot coordinates {
    (0.02, 0.192)
    (0.04, 0.67)
    (0.06, 0.8909)
    (0.08, 0.8624)
    (0.10, 0.7026)
    (0.12, 0.5396)
    (0.14, 0.4168)
\addlegendentry{  n=1e3 };
};

应该

\addplot coordinates {
    (0.02, 0.192)
    (0.04, 0.67)
    (0.06, 0.8909)
    (0.08, 0.8624)
    (0.10, 0.7026)
    (0.12, 0.5396)
    (0.14, 0.4168)
};
\addlegendentry{  n=1e3 }; % <-- moved down two lines

相关内容