tikz の凡例に線ではなくマークを表示する

tikz の凡例に線ではなくマークを表示する

使用する場合

    \addplot[color=black, mark=o, draw=none] table [y=Y, x=X]{Data/bottoms.dat};
    \addlegendimage{New record};
    \addplot[color=black, mark=x, draw=none] table [y=Y, x=X]{Data/breaks.dat};
    \addlegendentry{Discarded solution};
    \addplot[color=black, mark=*, draw=none] table [y=Y, x=X]{Data/restarts.dat};
    \addlegendentry{Reset to record}

「新しいレコード」、「破棄されたソリューション」、および「レコードにリセット」の横に表示されるラベルは単なる黒い線ですが、それぞれ「o」、「x」、「*」にしたいと思います。線の代わりにマークを表示するにはどうすればよいでしょうか。

答え1

このようなもの。コードとデータが提供されていないため、このソリューションでは3つのシンプルなデータファイルを作成し、を介してコードに組み込みますfilecontents。これらを追加します

\addlegendimage{only marks, mark=o}
\addlegendimage{only marks, mark=x}
\addlegendimage{only marks, mark=*}

legend cell align=centerその他のテキスト/ラベルの配置にはを使用します。

ここに画像の説明を入力してください

コード

\documentclass[tikz,border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}

\begin{filecontents}{data.dat}
X Y
1  3
2  4
\end{filecontents}

\begin{filecontents}{data2.dat}
X Y
3 5
4 6
\end{filecontents}

\begin{filecontents}{data3.dat}
X Y
5 7
6 8
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
%  width=\linewidth,
%  xmin=0,xmax=10,
%  ymin=0,ymax=10,
%  axis y line*=left,
%  axis x line*=bottom,
legend style={xshift=-2cm}  % adjustable
legend cell align=center,   % left,center, right, 
  ]

\addlegendimage{only marks, mark=o}
\addlegendimage{only marks, mark=x}
\addlegendimage{only marks, mark=*}

    \addplot[color=black, mark=o, draw=none] table [y=Y, x=X]{data.dat};
    \addlegendentry{\hspace{.3cm}New record};
    \addplot[color=black, mark=x, draw=none] table [y=Y, x=X]{data2.dat};
    \addlegendentry{\hspace{.3cm}Discarded solution};
    \addplot[color=black, mark=*, draw=none] table [y=Y, x=X]{data3.dat};
    \addlegendentry{\hspace{.3cm}Reset to record}
\end{axis}
\end{tikzpicture}
\end{document}

関連情報