Simple story with pgfplots and LaTeX

I was just looking for an hour to draw a simple function in LaTeX, for example f (x) = x ^ 2. The examples I tried do not work for some unknown reason, most likely due to the fact that pdflatex does not start gnuplot (the -enable-xxx options do not work), but I found the LaTeX package that works: pgfplots. The only problem is that the documentation does not have a simple example, like what I need. Yes, if I wanted to draw complex diagrams using something, then I could find something, but a really simple example of a function - no luck! But maybe I just need new glasses. So please, I would be happy to get a simple example of a functional graph in LaTeX with the x and y axis and the graph!

EDIT: I have found this best solution so far, but I am not satisfied yet, for example, the x mark is in the middle. I just want a standard plot without any fancy colors or 3d or the like.

\begin{tikzpicture}
\begin{axis}[
    axis x line=bottom,
    axis y line=middle,
    xlabel=$x$,
    ylabel={$x^2$},
    xmin=-4, xmax=4,
    ymin=0, ymax=4,
    width=0.8\textwidth,
    height=5cm
]
\addplot[mark=noner,smooth,domain=-1:1]{x^2};
\end{axis}
\end{tikzpicture}
+3
source share
2 answers

For simple functions you do not need Gnuplot, it pgfplotsis able to perform calculations in LaTeX. See Examples in section 4.2.4 of the manual pgfplots; in the first example, the function x ↦ x² - 4 is drawn.

+3
source

See section 4.8.2 (page 108) of the pgfplots manual .

+1
source

Source: https://habr.com/ru/post/1791079/