# pgfplots - disable smoothness

I am using following pgfplots to draw a simple function:

\begin{center}
\begin{tikzpicture}
\begin{axis}[
domain=-4:4,
xscale=2.25,yscale=1.125,
xmin=-4, xmax=4,
ymin=-2, ymax=2,
samples=500,
axis lines=center,
grid=both,
xtick={-4,-3,-2,-1,0,1,2,3,4}
]
\end{axis}
\end{tikzpicture}
\end{center}

It renders this plot:

As you see, the spikes are curved, although I have not used the "smooth" option in \addplot.

Does anyone know, if there is a way to make the spikes sharper?

(Sorry for my English.)

• If you write \pgfplotsset{compat=1.12} (or newer) into your preamble and compile the example with lualatex, it will also be fine. This makes use of the lua backend and has higher accuracy – Christian Feuersänger Jan 15 '16 at 18:50

One solution is determine enough large number of samples so, that will one lie at each spike. Then the obtained image is:

Code:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-4:4,
xscale=2.25,yscale=1.125,
xmin=-4, xmax=4,
ymin=-2, ymax=2,
samples=150,
axis lines=center,
grid=both,
xtick={-4,-3,-2,-1,0,1,2,3,4}
]

• I wonder if samples at could be chosen to give good results... – cmhughes Jan 14 '16 at 21:01
• samples at={-4,-3.9,...,-1,-0.99,-0.9,...,1,1.01,1.1,...,4} works pretty well and is only slightly tedious. – Jake Jan 14 '16 at 21:46