2

I have a scatter plot but I want to make a 3D plot where the points will be still in the XY plane but there will be a line over every point which will have different values for different (x,y) point.

Image 1

I could not find any suitable image so I had to draw one. I have tried to modify the code available in pgfplots.pdf (I have mentioned below), but could not manage to get what I am looking for. Any help? Thanks.

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    view={120}{40},
    width=420pt,
    height=420pt,
    %grid=major,
    %z buffer=sort,
    xmin=0,xmax=19,
    ymin=0,ymax=19,
    zmin=0,zmax=19,
    enlargelimits=upper,
    xtick={1,5,...,20},
    ytick={1,5,...,20},
    ztick={1,5,...,20},
    xlabel={$x$},
    ylabel={$y$},
    zlabel={$z$},
    %point meta={x+y+z+3},
    %colormap={summap}{
    %   color=(black); 
    %   color=(blue); 
        %color=(black); color=(white) 
        %color=(orange) color=(violet) 
        %color=(red)
    %},
    %scatter/use mapped color={
    %   draw=mapped color,fill=mapped color!70},
    ]
    % `pgfplots_scatter4.dat' contains a large sequence of
    % the form
    % l_0   l_1     l_2     
    % 1     6       -1      
    % -1    -1      -1      
    \addplot3[only marks,scatter,mark=cube*,mark size=7] 
        table {s.dat};
\end{axis}
\end{tikzpicture}

\end{document}

1 Answer 1

6

While this ought to be a zcomb type of plot, which doesn't exist so far, it works as expected when using ycomb:

Code

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
\begin{axis}
[   view={120}{40},
    xmin=0,xmax=3,
    ymin=0,ymax=3,
    zmin=0, zmax=5,
]
    \addplot3[only marks,ycomb,scatter,mark=cube*,mark size=7] table {s.dat};
\end{axis}
\end{tikzpicture}

\end{document}

Output

enter image description here


Edit 1: This is probably more what you want. I used a file s.dat with the contents

x   y   m
1   2   3
2   1   4
1   1   2
2   2   1

Where x and y are coordinates, and m is the meta information, i.e. the height of your line. Yo then need two plots: one with z set to zero and m used for coloring the cubes (if they should be colored), and a second one for the lines.

Code

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
\begin{axis}
[   view={120}{40},
    xmin=0,xmax=3,
    ymin=0,ymax=3,
    zmin=0, zmax=5,
]
    \addplot3[only marks, ycomb, scatter, mark=cube*, mark size=3, 
        point meta=explicit, z filter/.code={\pgfmathparse{0}\pgfmathresult},
] table[meta=m] {s.dat};
    \addplot3[mark=none, ycomb] table {s.dat};
\end{axis}
\end{tikzpicture}

\end{document}

Output

enter image description here

1
  • Thats exactly what was on my mind! U are a genius @Tom Bombadil!! :D
    – jhon_wick
    Oct 30, 2015 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .