# Improving a TikZ picture, which is based on a GeoGebra file

I want to do a little graphical illustration of fixed points of the cubic function. Hence, I made a GeoGebra file that looks like:

Based on that I would like to get a TikZ picture, so GeoGebra created the following code:

\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=3.393473219840507cm,y=3.1433709561724212cm, scale = 0.9, transform shape]
\begin{axis}[
x=3.393473219840507cm,y=3.1433709561724212cm,
axis lines=middle,
xmin=-1.3734914110429448,
xmax=1.62708588957055,
ymin=-1.1911483659319086,
ymax=1.353890101224171,
xtick={-1.0,0.0,1.0},
ytick={-1.0,0.0,1.0},]
\clip(-1.5734914110429448,-1.1911483659319086) rectangle (2.162708588957055,3.353890101224171);
\draw[line width=0.8pt,smooth,samples=100,domain=-1.5734914110429448:1.962708588957055] plot(\x,{(\x)^(3.0)});
\draw [line width=0.8pt,domain=-1.5734914110429448:1.962708588957055] plot(\x,{(-0.--1.*\x)/1.});
\draw (-1.3945119631901841,-0.6566295470542595) node[anchor=north west] {fixed point at $x = -1$};
\draw [->,line width=0.4pt] (-1.1269670132777865,-0.8093097675291255) -- (-1.0267447347382272,-0.9581246659666529);
\draw (1.1573010736196316,0.8952972509370971) node[anchor=north west] {fixed point at $x = 1$};
\draw (0.162066871165644,-0.20714781299805446) node[anchor=north west] {fixed point at $x = 0$};
\draw (1.3389923312883434,1.3508530624805482) node[anchor=north west] {$y = x$};
\draw (0.5803595092024538,1.3417419462496791) node[anchor=north west] {$f(x) = x^3$};
\draw (0.01834095092024525,1.36300121745504) node[anchor=north west] {$f(x)$};
\draw (1.5159338957055212,0.14514868126221436) node[anchor=north west] {$x$};
\draw [->,line width=0.4pt] (0.1593550613496931,-0.23144412294703853) -- (0.02376457055214709,-0.027962527124297032);
\draw [->,line width=0.4pt] (1.1491656441717788,0.843667592295506) -- (1.0298460122699384,0.9742602582712953);
\draw [line width=0.8pt,dash pattern=on 1pt off 1pt] (-1.,-1.)-- (-1.,0.);
\draw [line width=0.8pt,dash pattern=on 1pt off 1pt] (1.,1.)-- (1.,0.);
\begin{scriptsize}
\draw [fill=uuuuuu] (1.,1.) circle (2.0pt);
\draw [fill=uuuuuu] (-1.,-1.) circle (2.0pt);
\draw [fill=uuuuuu] (0.,0.) circle (2.0pt);
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}


That results in

which looks almost like I want it to look like apart from the texts (fixed point at …).

How can I improve the code in order to position the texts (fixed point at …) like in Figure 1 (including the linebreak after "at")? I tried a few little things but nothing seems to work.

• I would take that! I know it's certainly not the shortest or simplest way to do things like that, but it's the only way I can do it at the moment … – offline Apr 1 '19 at 10:19

This is a proposal.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[>=stealth,scale=3]
\draw[->] (0,-1.2)--(0,1.4) node[below right] {$f(x)$};
\draw[->] (-1.6,0)--(2,0) node[above left] {$x$};
\draw[thick] plot[samples=2,domain=-1.2:1.4] (\x,\x);
\draw[thick] plot[smooth,samples=500,domain=-1.06:1.12] (\x,\x^3);
\fill (-1,-1) circle (.5pt) coordinate (a) (0,0) circle (.5pt) coordinate (b) (1,1) circle (.5pt) coordinate (c);
\draw[dashed] (-1,-1)--(-1,0) (1,0)--(1,1);
\draw (-1,-.03) node[below] {$-1$}--(-1,.03) (1,-.03) node[below] {$1$}--(1,.03);
\draw (-.03,-1) node[left] {$-1$}--(.03,-1) (-.03,1) node[left] {$1$}--(.03,1);
\draw (1.1,{1.1^3}) node[left] {$f(x)=x^3$};
\draw (1.3,1.3) node[below right] {$y=x$};
\draw[<-] ($(a)+(150:.05)$)--++(150:.2) node[above left,align=left] {fixed point\\at $x=-1$};
\draw[<-] ($(b)+(-30:.05)$)--++(-30:.2) node[below right,align=left] {fixed point\\at $x=0$};
\draw[<-] ($(c)+(-30:.05)$)--++(-30:.2) node[below right,align=left] {fixed point\\at $x=1$};
\end{tikzpicture}
\end{document}


Some notes:

• \draw plot helps us draw plot even without pgfplots.
• Library calc helps us calculate coordinates. Read more here
• Nodes can be multi-line, however you need to add alignment option (align=...) and/or text width option. Read more here.
• @JouleV In this case I continue : [smooth,samples=500] is overfilling for x^3 and even in general. A pdf with only this curve for [smooth,samples=500] is 13k, [samples=500] is 6k and [smooth] is 2k. And you can't see the difference between this 3 curves. – Kpym Apr 2 '19 at 13:40