4

I'm wondering if it's possible using pgfplot to plot a 3D scatter plot with lines between each point where the point is replaced with a value. Image is shown below.

enter image description here

Currently I am populating the points on the graph via:

\begin{filecontents*}{table2.csv}
Name,X,Y,Z
0,    0,    0,    0
1,    0,    1 ,   0
2,    0,    2 ,   0
3,    0 ,   3  ,  0
\end{filecontents*}

\begin{tikzpicture}
    \begin{axis}[
    grid=both, xlabel=$X$,ylabel=$Y$,zlabel=$Z$,
    visualization depends on={value \thisrow{Name} \as \labela},
    nodes near coords={\labela},
    nodes near coords align={horizontal}
        ]

    \addplot3[scatter,only marks] table [x=X,y=Y,z=Z,col sep=comma] {table2.csv};

    \end{axis}
\end{tikzpicture}

enter image description here

percusse
  • 157,807

1 Answers1

7

You can use the mark type text and adjust accordingly. If the labels are just the coordinate indices of the points then you can use the readily available \coordindex macro instead without an extra column.

\begin{tikzpicture}
    \begin{axis}[
    grid=both, xlabel=$X$,ylabel=$Y$,zlabel=$Z$,
    visualization depends on={value \thisrow{Name} \as \labela},
        ]

    \addplot3[scatter,only marks,mark = text,
              mark options={text mark=\labela,
                            text mark as node=true,
                            text mark style={circle,inner sep=1pt,draw}
                            }
              ] 
    table [x=X,y=Y,z=Z,col sep=comma] {
    Name,X,Y,Z
    0,    0,    0,    0
    1,    0,    1 ,   0
    2,    0,    2 ,   0
    3,    0 ,   3  ,  0
    };
    \end{axis}
\end{tikzpicture}

enter image description here

percusse
  • 157,807