# Easiest way to draw a 3d coordinate system with axis labels and ticks in tikz

What's the easiest way to draw a 3d coordinate system in tikz with axis labels and ticks like the following one: • This diagram looks awfully crowded. Are you sure that's the output you want? You may prefer something like the example on pages 17-18 in the tikz-3dplot manual. In any case, the latter package is a good one for that kind of graphics. – jub0bs Jun 1 '13 at 13:14
• Yes I want it with ticks and labels (and control over it). – student Jun 1 '13 at 13:19

I used the xyz coordinate system:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}[x=0.5cm,y=0.5cm,z=0.3cm,>=stealth]
% The axes
\draw[->] (xyz cs:x=-13.5) -- (xyz cs:x=13.5) node[above] {$x$};
\draw[->] (xyz cs:y=-13.5) -- (xyz cs:y=13.5) node[right] {$z$};
\draw[->] (xyz cs:z=-13.5) -- (xyz cs:z=13.5) node[above] {$y$};
% The thin ticks
\foreach \coo in {-13,-12,...,13}
{
\draw (\coo,-1.5pt) -- (\coo,1.5pt);
\draw (-1.5pt,\coo) -- (1.5pt,\coo);
\draw (xyz cs:y=-0.15pt,z=\coo) -- (xyz cs:y=0.15pt,z=\coo);
}
% The thick ticks
\foreach \coo in {-10,-5,5,10}
{
\draw[thick] (\coo,-3pt) -- (\coo,3pt) node[below=6pt] {\coo};
\draw[thick] (-3pt,\coo) -- (3pt,\coo) node[left=6pt] {\coo};
\draw[thick] (xyz cs:y=-0.3pt,z=\coo) -- (xyz cs:y=0.3pt,z=\coo) node[below=8pt] {\coo};
}
% Dashed lines for the points P, Q
\draw[dashed]
(xyz cs:z=-5) --
+(0,7) coordinate (u) --
(xyz cs:y=7) --
+(-5,0) --
++(xyz cs:x=-5,z=-5) coordinate (v) --
+(0,-7) coordinate (w) --
cycle;
\draw[dashed] (u) -- (v);
\draw[dashed] (-5,7) -- (-5,0) -- (w);
\draw[dashed] (3,0) |- (0,5);

% Dots and labels for P, Q
\node[fill,circle,inner sep=1.5pt,label={left:$Q(-5,-5,7)$}] at (v) {};
\node[fill,circle,inner sep=1.5pt,label={above:$P(3,0,5)$}] at (3,5) {};
% The origin
\node[align=center] at (3,-3) (ori) {(0,0,0)\\\text{origin}};
\draw[->,help lines,shorten >=3pt] (ori) .. controls (1,-2) and (1.2,-1.5) .. (0,0,0);
\end{tikzpicture}

\end{document} A suggestion with pgfplots. There is an issue with the y-ticks though, as both horizontal and vertical lines are drawn, making the ticks a plus sign. Don't know why this happens.

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={35}{15},
axis lines=center,
width=15cm,height=15cm,
xtick={-10,-5,5,10},ytick={-10,-5,5,10},ztick={-10,-5,5,10},
minor tick={-12,-11,...,12},
xmin=-13,xmax=13,ymin=-13,ymax=13,zmin=-13,zmax=13,
xlabel={$x$-axis},ylabel={$y$-axis},zlabel={$z$-axis},
]

% plot dots for the two points
\addplot3 [only marks] coordinates {(-5,-5,7) (3,0,5)};

% plot dashed lines to axes
\addplot3 [no marks,densely dashed] coordinates {(0,0,5) (3,0,5) (3,0,0)};
\addplot3 [no marks,densely dashed] coordinates {(0,-5,0) (-5,-5,0) (-5,0,0) (-5,0,7) (0,0,7) (0,-5,7) (0,-5,0)};
\addplot3 [no marks,densely dashed] coordinates {(-5,0,7) (-5,-5,7) (0,-5,7)};
\addplot3 [no marks,densely dashed] coordinates {(-5,-5,0) (-5,-5,7)};

% label points
\node [above right] at (axis cs:3,0,5) {$P (3,0,5)$};
\node [above left] at (axis cs:-5,-5,7) {$Q (-5,-5,7)$};
\node [inner sep=2pt,outer sep=0pt] (O) at (axis cs:0,0,0) {};
\node [align=center] (origin) at ([xshift=1.5cm,yshift=-1.3cm]O) {$(0,0,0)$ \\Origin};
\draw [shorten <=.1cm,stealth-,gray] (O) to [out=-30,in=160] (origin.west);
\end{axis}
\end{tikzpicture}
\end{document} • Very nice solution. Do you know is there a way to have a projection like in Gonzalo's answer (x is strictly horizontal and z is strictly vertical), but using standard axis environment like in your answer? Thanks. – user35603 Jan 25 '18 at 12:13
• @user35603 Don't know, sorry. – Torbjørn T. Jan 25 '18 at 12:20