
Eu sou um novo usuário paraLotes PGFPentão tenho a seguinte dúvida: desenho uma elipse no TikZ e quero adicionar uma legenda para ela. No entanto, descobri que \addlegendentry
é apenas para \addplot
. Então, como posso adicionar uma legenda para minha curva?
\tikzsetnextfilename{1a}
\begin{tikzpicture}
\begin{axis}[
xlabel = $\dfrac{M}{M_{bend}}$,
ylabel = $\dfrac{P}{P_{burst}}$,
xmin=0,xmax=1.2,
ymin=0,ymax=1.2,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
label style={font=\tiny},
tick label style={font=\tiny},
legend style={font=\small},
legend cell align=left,
legend pos=north east
]
\addplot+[color=red,
line width=0.3mm]
(axis cs:0,0)
ellipse [
x radius=0.950052, y radius=0.945021];
\addlegendentry{Analytical results}
\end{axis}
\end{tikzpicture}
Eu li sobre a legenda personalizada de Personalize a posição da legenda no ambiente do eixo PGFplots, mas não tenho ideia de como colocar isso em um ambiente de eixo.
Responder1
Você pode usar \addlegendimage
para adicionar uma legenda para um \draw
comando. O argumento para \addlegendimage
é exatamente o mesmo parâmetro de estilo usado no draw
, por exemplo red,line width=0.3mm
. O problema de usar \draw
assim é que a escala está errada, pois não usa o sistema de coordenadas do arquivo axis
.
Outra opção aqui é plotar a elipse com addplot
, que fornece o tamanho correto.
\documentclass[tikz,border=5mm]{standalone}
\usepackage{pgfplots,amsmath}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel = $\dfrac{M}{M_{\mathrm{bend}}}$,
ylabel = $\dfrac{P}{P_{\mathrm{burst}}}$,
xmin=0,xmax=1.2,
ymin=0,ymax=1.2,
ymajorgrids=true,
xmajorgrids=true,
grid style=dashed,
label style={font=\tiny},
tick label style={font=\tiny},
legend style={font=\small},
legend cell align=left,
legend pos=north east
]
\draw[color=red,
line width=0.3mm]
(axis cs:0.6,0.6) % moved to middle of plot to make it more visible
ellipse [
x radius=0.950052, y radius=0.945021];
\addlegendimage{line width=0.3mm,color=red}
\addlegendentry{Analytical results}
\addplot [variable=\t,samples=200,domain=0:360] ({0.950052*cos(t)},{0.945021*sin(t)});
\addlegendentry{Parametric analytic}
\end{axis}
\end{tikzpicture}
\end{document}