图例未能显示正确的内容

图例未能显示正确的内容

我正在尝试绘制带有一些图例的图表。我有两个问题:

  1. 如果我使用\legend,那么它必须为上面的所有图提供图例。

  2. 如果我使用\addlegendentry,它不能给出正确的图形(下图)。

我该怎么做?

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[clip=false, xlabel=$1-\lambda$,ylabel={$\beta$},  ytick=\empty,xtick=\empty,
x label style={at={(1.05,0)},anchor=south},
y label style={at={(0.091,1)},anchor=north,rotate=270},
axis line style={draw=none}, legend style={at={(1.4,1.1)},legend cell align=right,legend plot pos=right}, area legend
]% coordinates
\addplot [domain=0:1, no marks, pattern=north west lines, area legend] {0.5} \closedcycle;\addlegendentry{$\beta \leq \frac{1}{2}$}

\addplot [name path=A,domain=0:1,black] {0.5};
\addplot [name path=B,domain=0:1,black,samples=300] {0.5+0.5*sqrt(1-x)};
\addplot [name path=C,domain=0:1,black,samples=300] {0.5*(2-x+sqrt(2*(1-x)+2*(1-x)^2))};

\addplot [pattern=dots, pattern color=green, draw=none,area legend] fill between [of=A and B];
\addlegendentry {$\frac{1}{2}<\beta \leq \frac{1}{2}(1+\sqrt{\lambda})$}

\addplot [
fill=blue, fill opacity=0.3,
draw=none,  area legend          
] fill between [of=B and C];\addlegendentry {$\frac{1}{2}(1+\sqrt{\lambda})<\beta<\frac{1}{2}(1+\lambda+\sqrt{2}\sqrt{\lambda+\lambda^2})$}

\addplot [ no marks] coordinates {(0,0) (0,2.5)} node[left,pos=1] {$+\infty$};
\addplot [ no marks] coordinates {(0,0) (1,0)} node[below, pos=1] {$1$};
\addplot [ no marks] coordinates {(1,0) (1,2.5)};
\addplot [ no marks] coordinates {(0,2.5) (1,2.5)};

\node [draw=none] at (rel axis cs: 0.04,0.04) {0};
\end{axis}
\end{tikzpicture}
\end{figure} 
\end{document}

在此处输入图片描述

相关内容