LaTex Plot Axis 3D

There are many packages in LaTeX to plot 3D, including tikz-3dplot, and other exotic packages.

The easiest one to use for plotting a simple 3D graph, with xyz axis and origin, is Pgfplots in my opinion.

The code to plot the diagram below is included for reference.

First, we need to add the following in the preamble of the LaTeX document:


Then, to draw the actual diagram, the following simple code will do:

  axis lines=center,

% plot dots for the points
\addplot3 [only marks] coordinates {(1,2,3) (4,5,6)};

% plot dashed lines to axes
\addplot3 [no marks,densely dashed] coordinates {(1,2,3) (4,5,6)};

% label points
\node [above] at (axis cs:1,2,3) {$A (1,2,3)$};
\node [above right] at (axis cs:4,5,6) {$B (4,5,6)$};
\node [below left] at (axis cs:0,0,0) {$O$};