1

I am plotting two data sets with curve fits added manually (by defining two functions). How can I edit my legend entry to combine the data points and lines into one icon? So instead of having four legend entries, I only have two.

  • 3
    It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Jun 13 '13 at 12:35
3

an example would have been great. Without I have to guess how you want it. I have some sample code here, have a look if it is what you need.

\documentclass{scrartcl}

\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\usetikzlibrary{plotmarks}
\usepgfplotslibrary{external}
\tikzexternalize

\begin{document}

\tikzset{external/remake next}
\begin{tikzpicture}

\begin{axis}[%
width=6cm,
height=4cm,
scale only axis,
line join=round,
xmin=0,
xmax=12,
ymin=-0.25,
ymax=0.25,
legend style={draw=black,fill=white,legend cell align=left}
]

\addplot [
color=red,
mark=x,
only marks,
forget plot
]
table[row sep=crcr]{
0 0.22439196264301\\
1 0.203635954610048\\
2 0.145263853838474\\
3 0.0600692256042584\\
4 -0.0362016489987046\\
5 -0.125760125036079\\
6 -0.192062139836642\\
7 -0.222864398803253727\\
};

\addplot [
color=red,
solid,
line width=1pt,
forget plot
]
table[row sep=crcr]{
0 0.22439196264301\\
7 -0.222864398803253727\\
};

\addplot [
color=red,
mark=x,
solid,
line width=1pt]
table[row sep=crcr]{
-1 -1\\
};
\addlegendentry{myEntry};


\end{axis}
\end{tikzpicture}%

\end{document}
  • Instead of adding a dummy plot to create the legend, I would put legend image post style={sharp plot, draw=red, line width=1pt, mark options={black, thin}} in the first plot's options to specify how to draw the legend entry. – Jake Jun 13 '13 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.