2

I have a plot in which I am showing experimentally obtained data and different models for the data. In order to keep the legend clean I want to summarise slightly different versions of the same model under one legend entry.

I came accross this similar question, but the proposed solution leads to all legend images being changed to the one given in legend image code/.code. I also tried adding empty legend entries but that leads to the label being aligned with the first legend image.

Here is an MWE with the current legend:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}

\begin{axis}[ legend cell align={left}, legend style={at={(0.98,0.02)}, anchor=south east, draw=black}, xmin=0, xmax=1, ymin=0, ymax=1, ] \addlegendimage{only marks, black, mark=square} \addlegendentry{Experiment}; \addlegendimage{blue} \addlegendentry{Model 1-1}; \addlegendimage{blue,dashed} \addlegendentry{Model 1-2}; \addlegendimage{blue, dotted} \addlegendentry{Model 1-3}; \addlegendimage{only marks, blue, mark=x} \addlegendentry{Model max}; \addlegendimage{red} \addlegendentry{Model 2} \addplot [black, mark=square, mark options={solid}, only marks] table {% 0 0.1 0.25 0.4 0.5 0.6 0.75 0.7 1 0.9 }; \addplot [blue] table {% 0 0 1 1.5 }; \addplot [blue, dashed] table {% 0 0 1 0.9 }; \addplot [blue, dotted] table {% 0 0 1 0.7 }; \addplot [blue, mark=x, mark options=solid, only marks] table {% 1 0.95 }; \addplot [red] table {% 0 0 0.1 0.3 0.2 0.5 0.3 0.6 0.4 0.65 0.5 0.7 1 1 }; \end{axis} \end{tikzpicture} \end{document}

Output from MWE

And this is what I want my legend to look like:

Desired legend

drachis
  • 21

0 Answers0