pgfplots: Distributing random points on surface

I want to distribute some random points on a surface. My working example looks like this:

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
view={10}{25},
ticks = none,
grid=major,
xlabel=$x$,
ylabel=$y$,
zlabel={$z$},
]

surf,
opacity=0.8,
samples=50, samples y=30,
domain=-1:1,y domain=-1:1,
z buffer=sort,
]
{x^2+x};

\end{axis}
\end{tikzpicture}
\end{document}


But this isn't what I'm looking for because the points are not distributed randomly. Also it would be nice to have the points round and a lot smaller.

I think, this is, what you are searching for, right?

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
% load the ColorBrewer library to use another colormap
\usetikzlibrary{
pgfplots.colorbrewer,
}
\pgfplotsset{
compat=1.3,
% declare some constants for the min and max values of the x and y axis
% to be later used in the "random" columns and the domain's for the
% functions
/pgf/declare function={
xmin=-1;
xmax=1;
ymin=-1;
ymax=1;
},
}
\begin{document}
% because tikz/pgf(plots) can only produce pseudo-random numbers,
% change the following number to produce other ones
\pgfmathsetseed{7}
% create a table that will later be used to plot the "random" points
\pgfplotstableset{
% create the random numbers for the x and y values
% here they are declared generally, so it will also work when you will
% change the limits of the x and y values
create on use/randomx/.style={
create col/expr={(xmax-xmin)*rnd + xmin}
},
create on use/randomy/.style={
create col/expr={(ymax-ymin)*rnd + ymin}
},
% and here we calculate the corresponding z' values
% (adapt the expression, when the formula is changing)
create on use/z/.style={
create col/expr={(\thisrow{randomx})^2 + \thisrow{randomx}}
},
}
% initialise a table with a certain number of rows and "fill it" with
% the former created columns
\pgfplotstablenew[
columns={randomx,randomy,z},
]{100}\loadedtable       % <-- How many points to you want to plot?
% uncomment the following line to typeset the former table
\begin{tikzpicture}
\begin{axis}[
view={-20}{25},
%            view={0}{90},   % <-- to view from top how the random points are distributed
ticks=none,
grid=major,
xlabel=$x$,
ylabel=$y$,
zlabel={$z$},
colormap/YlGnBu,
]

surf,
opacity=0.8,
samples=50,
samples y=30,
domain=xmin:xmax,
y domain=ymin:ymax,
z buffer=sort,
] expression {x^2+x};

% plot the table with the "random" points
only marks,
mark=*,
% change the mark size to a value that fits your needs
mark size=1pt,
% use scatter' to plot the points in the same color
% as the corresponding surf' point
scatter,
] table [
x=randomx,
y=randomy,
z=z,

• At the corresponding \addplot it is stated why the colors are identical, so it shouldn't be that hard, right? Otherwise your question is quite vague what you understand under "independent". May 10, 2020 at 0:10
• I'm sorry, my bad. I thought it'd point lines if you didn't include scatter. May 10, 2020 at 0:24