使用 tikz 添加点及其相关图例

使用 tikz 添加点及其相关图例

下面的代码

\begin{tikzpicture}[scale=0.7]
\begin{axis}[xlabel={$s$},ylabel={$c$},legend pos=south east]
\addlegendimage{empty legend}
\addlegendentry{}
\addplot+[smooth,draw=black,mark=oplus] coordinates
{(0.3,0.275)};
\addlegendentry{$\zeta=10$}
\addplot+[smooth,draw=black,mark=oplus] coordinates
{(0.2,0.15)};
\addlegendentry{$\zeta=10$}
\addplot+[smooth,draw=black,mark=x] coordinates
{(0.345743, 0.332178)};
\addlegendentry{$\zeta=15$}
\addplot+[smooth,draw=black,mark=x] coordinates
{(0.154257, 0.0928216)};
\addlegendentry{$\zeta=15$}
\end{axis}
\end{tikzpicture}

产生下面的图片:

在此处输入图片描述

在图例中,我希望对不同类型的点只使用一种描述。例如,我们有案例 10 和 15 重复两次。正确的图片应该是:

在此处输入图片描述

编辑

但是,代码:

\begin{tikzpicture}[scale=0.7]
\begin{axis}[xlabel={$s$},ylabel={$c$},legend pos=south east]
\addlegendimage{empty legend}
\addlegendentry{}
\addplot+[smooth,draw=black,mark=oplus] coordinates
{(0.3,0.275)};
\addplot+[smooth,draw=black,mark=oplus] coordinates
{(0.2,0.15)};
\addlegendentry{$\zeta=10$}
\addplot+[smooth,draw=black,mark=x] coordinates
{(0.345743, 0.332178)};
\addplot+[smooth,draw=black,mark=x] coordinates
{(0.154257, 0.0928216)};
\addlegendentry{$\zeta=15$}
\addplot+[smooth,draw=black,mark=o] coordinates
{(0.361803,0.352254)};
\addplot+[smooth,draw=black,mark=o] coordinates
{(0.138197, 0.0727458)};
\addlegendentry{$\zeta=20$}
\addplot+[smooth,draw=black,mark=square] coordinates
{(0.370416, 0.36302)};
\addplot+[smooth,draw=black,mark=square] coordinates
{(0.129584, 0.0619801)};
\addlegendentry{$\zeta=25$}
\end{axis}
\end{tikzpicture}

不能解决我的问题:

在此处输入图片描述

答案1

永远不要忘记选项forget plot,它允许您忽略图例中的情节。我将其添加到其他每个图例中,以获得

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[scale=0.7,xlabel={$s$},ylabel={$c$},legend pos=south east]
\addlegendimage{empty legend}
\addlegendentry{}
\addplot+[smooth,draw=black,mark=oplus] coordinates
{(0.3,0.275)};
\addplot+[smooth,draw=black,mark=oplus,forget plot] coordinates
{(0.2,0.15)};
\addlegendentry{$\zeta=10$}
\addplot+[smooth,draw=black,mark=x] coordinates
{(0.345743, 0.332178)};
\addplot+[smooth,draw=black,mark=x,forget plot] coordinates
{(0.154257, 0.0928216)};
\addlegendentry{$\zeta=15$}
\addplot+[smooth,draw=black,mark=o] coordinates
{(0.361803,0.352254)};
\addplot+[smooth,draw=black,mark=o,forget plot] coordinates
{(0.138197, 0.0727458)};
\addlegendentry{$\zeta=20$}
\addplot+[smooth,draw=black,mark=square] coordinates
{(0.370416, 0.36302)};
\addplot+[smooth,draw=black,mark=square,forget plot] coordinates
{(0.129584, 0.0619801)};
\addlegendentry{$\zeta=25$}
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容