Graphics, Figures & TablesBalls as Plot Marks

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Enzo
Posts: 4
Joined: Sun Jan 05, 2014 2:03 pm

Balls as Plot Marks

Post by Enzo »

Hi,

I want to use a ball as a marker in a 3D plot. My code looks like this.

Code: Select all

\begin{tikzpicture}
  \pgfdeclareplotmark{ball}{%
    \shade[draw=none,ball color=red] (0,0) circle (\pgfplotmarksize);
  }

  \begin{axis}[colormap/bluered]
    \addplot3+[
      z buffer=sort,
      scatter,
      scatter src=d,
      only marks,
      mark options={mark=ball,scale=0.9}
    ] table [x=a,y=b,z=c,meta=d]{data.csv};
  \end{axis}
\end{tikzpicture}
The question is: how to replace the ball color (red) by the data color defined by scatter src?

Thanks,

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

feuersaenger
Posts: 34
Joined: Sun Oct 16, 2011 5:56 pm

Balls as Plot Marks

Post by feuersaenger »

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.
Attachments
P.png
P.png (23.25 KiB) Viewed 9338 times
Enzo
Posts: 4
Joined: Sun Jan 05, 2014 2:03 pm

Re: Balls as Plot Marks

Post by Enzo »

Thanks !
Post Reply