How to insert a vertical line as legend entry for a vertical graph

by Sral   Last Updated October 09, 2019 15:23 PM

I have two graphes, one horizontal (y1) and one vertical (y2) line. For a better identification in the legend, I want the vertical graph (y2) also to be represented by a vertical line in the legend. In other words: left to y2 should be a vertical dashed line (rotation of 90°), while the y1 legend entry stays as it is.

Is there any way to customize the appearance of the legend entry symbols like that? Thank you very much for your help!

the handdrawn is how the legend entry should look like (maybe a bit more professional)

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=5,
ymin=0,
ymax=5,
axis background/.style={fill=white},
legend entries={y1,y2},
]
\addplot [color=black, dashdotted]
  table[row sep=crcr]{%
0   3\\
5   3\\
};
\addplot [color=black, dashed]
  table[row sep=crcr]{%
0   -100\\
2   100\\
};
\end{axis}
\end{tikzpicture}
\end{document}
Tags : pgfplots legend


Related Questions



Legend entry not showing correct image

Updated June 28, 2015 15:10 PM

Adding a legend next to subfigures of pgfplots

Updated March 21, 2016 08:09 AM

How to only show legend in pgf plot?

Updated August 05, 2015 16:10 PM

Tikz pictures disappears when adding legend

Updated May 11, 2016 08:09 AM