# Fine-tuning a function plot using pgfplots

I have some problems to find the right options in the 566 pages of the manual. In the plot I would like to achieve that

• the curve is smoother (increasing the number of samples results in the error "Dimension too large");
• the labels x and y are placed below and left of the axes, respectively;
• the gray grid is shown across the whole coordinate system with a distance of 1 unit in each direction although there is only one tick and one label on each axis.

This is the code that produces the above image.

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.15}
% \pgfplotsset{samples=512}

\begin{document}

\begin{tikzpicture}
\begin{axis}
[
grid = major,
axis x line = middle, axis y line = middle,
xlabel = $x$, xmin = -6, xmax = 6, xtick = {1},
ylabel = $y$, ymin = -3, ymax = 6, ytick = {1},
]
\addplot[domain = -6 : 6] {-2 * (x + 3) * (x - 3) / x^2};
\end{axis}
\end{tikzpicture}

\end{document}


See comments in the code for ticks and grid settings.

You can use smooth to make the plot smoother in this case, but in general be a bit careful with it. See How to create a Ricker Wavelet in TikZ and pgfplots, overshooting problem for examples of smooth gone bad. \documentclass{article}

\pgfplotsset{compat=1.15}
\begin{document}

\begin{tikzpicture}
\begin{axis}
[
grid = major,
axis x line = middle, axis y line = middle,
xlabel = $x$, xmin = -6, xmax = 6,
% xticks every 1 unit, remove all labels
xtick distance = 1, xticklabels={},
ylabel = $y$, ymin = -3, ymax = 6,
% yticks every 1 unit, remove all labels
ytick distance = 1, yticklabels={},
% append below left to styles of both axis labels
ylabel style={below left}, xlabel style={below left},
% add extra ticks at 1, which will have labels
extra x ticks={1},extra y ticks={1},
% we get extra grid lines for the extra ticks, disable those and make ticks black
extra x tick style={grid=none,tick style=black},
extra y tick style={grid=none,tick style=black},
% black instead of grey ticks
tick style={black},
]

• @Matthias The grid is below, but the ticks are grey. tick style={black} makes them black. Needs some extra stuff for the extra ticks, will edit shortly. – Torbjørn T. Dec 11 '17 at 22:09