Graphen beschriften GnuPlot und tikz

Graphen beschriften GnuPlot und tikz

Ich versuche, einige Diagramme zu beschriften, aber ich komme einfach nicht dahinter. Ich versuche, etwas zu bekommen, das ungefähr so ​​aussieht:

Bildbeschreibung hier eingeben

Gefunden auf der texanmple-WebsiteHier. Ich möchte die Funktion, die jedem Diagramm entspricht, wie in der Abbildung oben gezeigt beschriften.

Das ist, was ich habe:

\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}

was ergibt:

Bildbeschreibung hier eingeben

Ich hatte gehofft, aus Stilgründen in der Achsenumgebung zu bleiben.

Antwort1

Hier ist eine Lösung, die ein nodeentlang der Kurve positioniert; variieren Sie den posSchlüssel zwischen 0(Domänenanfang) und 1(Domänenende) nach Belieben. Sie können auch mit dem Anker spielen, z. B. east, west, usw.

Bildbeschreibung hier eingeben

% 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}

Als Referenz hier eine Version ohnegnuplot

% 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}

Wenn Sie die Beschriftungen außerhalb der Achse haben möchten, sehen Sie sich Folgendes an:PgfPlots mit beschrifteten Plots erstrecken sich über den Diagrammrahmen hinaus.

Antwort2

Du kannst der pgfplot-Achse wie folgt eine Legende hinzufügen. Reicht das? Oder geht es dir um die Farbgebung des Legendentextes?

\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}

Bildbeschreibung hier eingeben

verwandte Informationen