
일부 플롯에 레이블을 지정하려고 하는데 알아낼 수 없는 것 같습니다. 나는 다음과 같은 것을 얻으려고 노력하고 있습니다.
texanmple 웹사이트에서 찾았습니다.여기. 위 그림과 같이 각 플롯에 해당하는 함수에 라벨을 붙이고 싶습니다.
이것이 내가 가진 것입니다:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
\begin{axis}[
minor y tick num=2,
minor x tick num=1,
extra y ticks={0},
extra x ticks={0},
extra tick style={grid style={black},xticklabel=\empty},
width=0.7\textwidth,
ymin=-2, ymax=2,
grid=both, y=1cm,
axis y line=left,
axis x line=bottom
]
\addplot gnuplot [plot, samples=500, restrict y to domain=-10:10] {
plot [-5:5] x**3 - x;
};
\addplot gnuplot [plot, blue, samples=500, restrict y to domain=-10:10] {
plot [-5:5] (x-3)**3 - (x-3);
};
\addplot gnuplot [plot, red, samples=500, restrict y to domain=-10:10] {
plot [-5:5] (x+3)**3 - (x+3);
};
\end{axis}\end{tikzpicture}
\end{document}
이는 다음을 생성합니다.
스타일상의 이유로 축 환경에 머물기를 바랐습니다.
답변1
node
곡선을 따라 위치를 지정하는 솔루션은 다음과 같습니다 . 적절하다고 판단되는 대로 (도메인 시작)과 (도메인 끝) pos
사이의 키를 변경하세요 . , 등 의 앵커를 가지고 놀 수도 있습니다 .0
1
east
west
% arara: pdflatex: {shell: yes}
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
\begin{axis}[
minor y tick num=2,
minor x tick num=1,
extra y ticks={0},
extra x ticks={0},
extra tick style={grid style={black},xticklabel=\empty},
ymin=-2, ymax=2,
grid=both, y=1cm,
axis y line=left,
axis x line=bottom
]
\addplot gnuplot [plot, samples=500, restrict y to domain=-10:10] {
plot [-2:2] x**3 - x;
}node[pos=0.7,anchor=west]{$y=f(x)$};
\addplot gnuplot [plot, blue, samples=500, restrict y to domain=-10:10] {
plot [1:5] (x-3)**3 - (x-3);
}node[pos=0.3,anchor=west]{$y=g(x)$};
\addplot gnuplot [plot, red, samples=500, restrict y to domain=-10:10] {
plot [-5:-1] (x+3)**3 - (x+3);
}node[pos=0.7,anchor=east]{$y=h(x)$};
\end{axis}\end{tikzpicture}
\end{document}
참고로 없는 버전이 있습니다.gnuplot
% arara: pdflatex
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[plot/.style={very thick,mark=none,black,samples=100}]
\begin{axis}[
minor y tick num=2,
minor x tick num=1,
extra y ticks={0},
extra x ticks={0},
extra tick style={grid style={black},xticklabel=\empty},
ymin=-2, ymax=2,
grid=both, y=1cm,
axis y line=left,
axis x line=bottom
]
\addplot [plot,domain=-2:2]{x^3 - x}node[pos=0.7,anchor=west]{$y=f(x)$};
\addplot [plot,blue, domain=1:5] { (x-3)^3 - (x-3)}node[pos=0.3,anchor=west]{$y=g(x)$};
\addplot [plot,red, domain=-5:-1] {(x+3)^3 - (x+3)}node[pos=0.7,anchor=east]{$y=h(x)$};
\end{axis}
\end{tikzpicture}
\end{document}
마지막으로 축 외부에 레이블을 추가하려면 다음을 살펴보세요.레이블이 지정된 플롯이 있는 PgfPlot은 그래프 상자 외부로 확장됩니다..
답변2
다음과 같이 pgfplot 축에 범례를 추가할 수 있습니다. 이것이 충분하나요? 아니면 범례 텍스트의 색상을 지정하고 계십니까?
\documentclass[tikz,border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
\begin{axis}[
minor y tick num=2,
minor x tick num=1,
extra y ticks={0},
extra x ticks={0},
extra tick style={grid style={black},xticklabel=\empty},
width=0.7\textwidth,
ymin=-2, ymax=2,
grid=both, y=1cm,
axis y line=left,
axis x line=bottom,
legend style={at={(1.1,1)}, anchor={north west}},
]
\addplot gnuplot [plot, samples=500, restrict y to domain=-10:10] {
plot [-5:5] x**3 - x;
};
\addplot gnuplot [plot, blue, samples=500, restrict y to domain=-10:10] {
plot [-5:5] (x-3)**3 - (x-3);
};
\addplot gnuplot [plot, red, samples=500, restrict y to domain=-10:10] {
plot [-5:5] (x+3)**3 - (x+3);
};
\legend{$ x^3 - x $,$ (x-3)^3 - (x-3) $,$ (x+3)^3 - (x+3) $}
\end{axis}\end{tikzpicture}
\end{document}