
나는 새로운 사용자입니다PGFP롯그래서 다음과 같은 질문이 있습니다. TikZ에 타원을 그리고 이에 대한 범례를 추가하고 싶습니다. 그러나 나는 \addlegendentry
가 \addplot
. 그렇다면 내 곡선에 대한 범례를 어떻게 추가할 수 있나요?
\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}
맞춤형 범례에 대해 읽었습니다. PGFplots 축 환경에서 범례 위치 사용자 정의, 그러나 이것을 축 환경에 배치하는 방법에 대해서는 전혀 모릅니다.
답변1
\addlegendimage
명령 에 대한 범례를 추가하는 데 사용할 수 있습니다 \draw
. 에 대한 인수는 \addlegendimage
에서 사용된 것과 동일한 스타일 매개변수입니다 draw
(예: ) red,line width=0.3mm
. 그러나 이와 같이 사용할 때의 문제점은 \draw
의 좌표계를 사용하지 않기 때문에 배율이 잘못되었다는 것입니다 axis
.
여기서 또 다른 옵션은 를 사용하여 타원을 플롯하는 것인데 addplot
, 이는 올바른 크기를 제공합니다.
\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}