
Estoy tratando de etiquetar algunas tramas pero parece que no puedo entenderlo. Estoy intentando conseguir algo que se parezca un poco a esto:
Encontrado en el sitio web de texanmpleaquí. Me gustaría etiquetar la función correspondiente a cada gráfico como se muestra en la figura anterior.
Esto es lo que tengo:
\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}
que produce:
Esperaba permanecer en el entorno del eje por razones de estilo.
Respuesta1
Aquí hay una solución que coloca una node
posición a lo largo de la curva; varíe la pos
clave entre 0
(principio de dominio) y 1
(fin de dominio) como mejor le parezca. También puedes jugar con el ancla, por ejemplo east
, , west
, etc.
% 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}
Como referencia, aquí hay una versión singnuplot
% 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}
Finalmente, si desea que las etiquetas estén fuera del eje, eche un vistazo aPgfPlots con gráficos etiquetados se extienden fuera del cuadro del gráfico.
Respuesta2
Puede agregar una leyenda al eje pgfplot de la siguiente manera. ¿Es suficiente? ¿O buscas colorear el texto de la leyenda?
\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}