I have an axis which contains several plots. These plots can be divided into two groups, of which each has a common plot marker. The plots are styled using a combined cycle list.
I would then like to create a legend, which shows all entries without their markers and instead include the markers in manually created "group headlines" inside the legend. Hopefully, my MWE can explain, what I mean:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymax=2,
cycle multiindex* list={
mark=square,mark=o\nextlist
color list
},
legend style={mark options={no markers}},
legend image code/.code={
\draw[domain=0:0.8, mark repeat=12,mark phase=7, mark size=1.5,#1]
plot (\x cm,{0.05cm*sin((\x r)*2*pi/0.8)});
}
]
\addlegendimage{empty legend} % This should produce a single square marker instead
\addlegendentry{Headline 1}
\addplot table {
0 0
1 1
};
\addlegendentry{Data 1 }
\addlegendimage{empty legend} % This should produce a single circle marker instead
\addlegendentry{Headline 2}
\addplot table {
0 0
1 0.5
};
\addlegendentry{Data 2}
\end{axis}
\end{tikzpicture}
\end{document}
These markers are added via MS Paint, to illustrate what I am looking for. I have also redefined legend image code
(inspired by the data visualization tikz library) and would like to keep this for reasons of consistency with my other plots. I also do not want my cycle list to be affected by the insertion of the headlines.
What would be the most straightforward way to do this? I have tried to hack myself around it by using "invisible" plots (using only markers
and mark options={scale=0}
) but this also renders the legend entries invisible.
Do I have to define my own legend style to use in this case?
This could probably be solved, if I set the legend style={mark options={no markers}}
individually for every plot instead of the axis options. But this seems a little cumbersome to me and I still wouldn't know how to add invisible plots that only show up inside the legend.