Hi
Enzo,
There are two key point here: one is the 'mapped color'; it is always redefined to the actual value of the color map.
The second is surprisingly difficult to find; it is the way how the mapped color is consumed. One has to say
scatter/use mapped color={ball color=mapped color}
. Apparently, this key is the only one which is re-evaluated for every marker, i.e. a simple
mark options={ball color=mapped color}
is evaluated only once at the beginning.
Here is your example with these options. I had to rewrite it somehow such that it becomes compilable.
Code: Select all
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
% \pgfdeclareplotmark{ball}{%
% \shade[draw=none,shading=ball] (0,0) circle (\pgfplotmarksize);
% }
\begin{axis}[colormap/bluered,colorbar]
\addplot3+[
samples=4,
z buffer=sort,
scatter/use mapped color={ball color=mapped color},
scatter,
scatter src=rand,
only marks,
mark=ball,
mark size=3pt,
] {0};
\end{axis}
\end{tikzpicture}
\end{document}
Note that I eliminated the
mark options
section since these options are now in the list for
scatter/use mapped color
. The
mark size
is optional; but may be of interest -- feel free to restore your original
scale
option if this suggestion is inadequate.
Note that TikZ already defines a
mark=ball
, so you do not need to define it on your own.