I would lie to make a legend where the legend marker is the fill of the area. However, when filling between two curves in pgfplots
the lines are defined before the fill, so I have idea how to do this.
My current MWE
:
\documentclass[border=0.5]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathtools,amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
mark = none,
axis equal,
xmin = 0,
xmax = 2,
ymin = 0,
ymax = 2,
]
\addplot[pattern= dots, samples = 3, domain = 0:1, pattern color = red] {1}\closedcycle;
\addplot+[name path global = A, color = black, mark=none, domain = 1:2] {1};
\addplot+[name path global = B, color = black, mark=none, domain = 1:2] {2};
\addplot[pattern = north west lines, pattern color = green] fill between[of=A and B];
\draw [color = black] (axis cs:1,1) -- (axis cs:1,2);
\draw [color = black] (axis cs:2,1) -- (axis cs:2,2);
\filldraw [color = blue] (axis cs:1,1) circle (0.005);
\legend{ First electron, Other electron}
\end{axis}
\end{tikzpicture}
\end{document}
Where I would like the black lines to be the pattern of the squares.
Thanks in advance 😉
P.S.: I do realize that the current legend placement is horrible, but no point in moving it if I would rather explain myself in a caption 😉
Best Answer
So you want do do something like the following?
For details please have a look at the comments in the code.