Add these to your code.
\pgfplotsset{
compat=1.11,
legend image code/.code={
\draw[mark repeat=2,mark phase=2]
plot coordinates {
(0cm,0cm)
(0.15cm,0cm) %% default is (0.3cm,0cm)
(0.3cm,0cm) %% default is (0.6cm,0cm)
};%
}
}
Change the values as you wish.
You can use legend image post style={scale=0.5},
. For details, consult page 261 of pgfplots
manual (version 1.17).
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={\tiny X},
ylabel={\tiny Y},
xmin=0, xmax=5,
ymin=0, ymax=18,
minor x tick num=4,
minor y tick num=4,
ytick={0, 2, 4, 6, 8, 10, 12, 14, 16, 18},
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd,
font=\tiny},
x tick label style={font=\tiny},
every x tick/.style={color=black, thin},
every y tick/.style={color=black, thin},
xtick pos=left,
ytick pos=left,
axis on top,
width=5cm,
height=5cm,
legend image post style={scale=0.5}, %%% <--- here
legend style={at={(0.97,0.03)}, anchor=south east},
clip mode=individual
]
\addplot+[
color=red,
solid,
line width=1.0pt,
mark=star,
mark options={mark size=4pt,solid, line width=0.5pt}, %% make size 4pt for demo
error bars/.cd, y dir=both,y explicit]
plot coordinates {
(0, 1)
(1, 2)
(2, 4)
(3, 8)
(4, 16)
};
\addlegendentry{My plot};
\end{axis}
\end{tikzpicture}
\end{document}
Another option is to use forget plot
in the \addplot+
options and the add
\addlegendimage{red,line width=1.0pt,,mark=star,mark options={mark size=2pt,solid, line width=0.5pt}};
\addlegendentry{My plot};
Best Answer
I found the answer, by adding 'only marks' to the legend setting. The plots still has a line, but it shows only marker in the legend.