# How to sample a function non-uniformly?

See this example code:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-0.1,
xmax=1.1,
ymin=-1.1,
ymax=1.1,
domain=0:1,
samples=30
]
\end{axis}
\end{tikzpicture}
\end{document}


The result appears acceptable far from zero, but near zero it's too much undersampled:

Increasing samples value makes the plot nice, but it considerably slows down processing. As a workaround I could just plot the inverse in a parametric plot (i.e. (y^2,y)), but in my actual code it'd require quite a bit of additional work.

Is there a way to provide a custom sampling function or specify different density of samples in different parts of the domain?

samples and domain can be used as plot options and you can repeat same function for several domains. This is not a solution but more a workaround. An example is shown as upper part (orange+blue) in following graph.

Another option (suggested by percusse) consists in specifying samples with samples at option. This options follows a foreach (TikZ - pgffor) syntax. An example is shown as lower part (purple) below.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-0.1,
xmax=1.1,
ymin=-1.1,
ymax=1.1,
domain=0:1,
% samples=30
]

• Or you can go about it with samples at={0,0.005,...,0.1,0.15,...,1} Mar 8, 2016 at 8:51