[Tex/LaTex] 3D Cartesian Coordinate System

3dcoordinatespgfplotstikz-pgf

I want to modify my three-dimensional Cartesian coordinate system as shown in the picture attached.

  1. I would like to have numbers under my ticks.
  2. I want parts of the grid to be parallel to the x_1 axis.

What changes have to be made to my code?

enter image description here

MWE:

\documentclass{scrartcl}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{center}
\begin{tikzpicture}
\draw[gray!60!white, thick] (-4.99,-4.99) grid (9.99,9.99);
\draw[->, >=latex, ultra thick] (0,0,-2.6) -- (0,0,13) node[left]{$x_1$};
\draw[->, >=latex, ultra thick] (0,0,0) -- (10,0,0) node[below]{$x_2$};
\draw[->, >=latex, ultra thick] (0,0,0) -- (0,10,0) node[left]{$x_3$};
\foreach \z in {2.6,5.2,7.8,10.4}
\draw[shift={(0,0,\z)}, ultra thick] (0pt,0pt,0pt) -- (0pt,-0.21pt,0pt);
\foreach \x in {2,4,6,8}
\draw[shift={(\x,0)}, ultra thick] (0pt,0pt) -- (0pt,-6pt);
\foreach \y in {2,4,6,8}
\draw[shift={(0,\y)}, ultra thick] (0pt,0pt) -- (-6pt,0pt);
\draw[fill=green!50!white, nearly transparent] (0,0,0) -- (0,0,12.7) -- (0,9.9,12.7) -- (0,9.9,0);
\draw[fill=blue!50!white, nearly transparent] (0,0,0) -- (9.9,0,0) -- (9.9,9.9,0) -- (0,9.9,0);
\draw[fill=red!50!white, nearly transparent] (0,0,0) -- (9.9,0,0) -- (9.9,0,12.7) -- (0,0,12.7);
\draw[blue, ultra thick, ->] (4,0,5.2) -- (4,4,5.2);
\draw[red, ultra thick, ->] (0,0,5.2) -- (4,0,5.2);
\draw[green, ultra thick, ->] (0,0,0) -- (0,0,5.2);
\shade[ball color=yellow] (4,4,5.2) circle (0.2);
\end{tikzpicture}
\end{center}

\end{document}

Best Answer

With some styles and declare function for constants. The grids are drawn manually with one loop, the ticks with labels with a second loop. Use the scale parameter to adjust the size of the diagram.

enter image description here

\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}

\begin{center}
\begin{tikzpicture}[
  scale=2,
  axisstyle/.style={
    ->,
    >=latex,
    ultra thick
  },
  gridstyle/.style={
    gray!60!white, thick
  },
  tickstyle/.style={
    ultra thick
  },
  axisbg/.style={
    fill=#1!50,
    nearly transparent
  },
  arrows/.style={
    ultra thick,
    ->,
    #1
  },
  declare function={
    ticklen=0.15;
    xmax=5;
    ymax=5;
    zmax=5;
  },
]    

\draw[axisstyle] (0,0,-1) -- (0,0,zmax) node[left]{$x_1$};
\draw[axisstyle] (0,0,0) -- (xmax,0,0) node[below]{$x_2$};
\draw[axisstyle] (0,0,0) -- (0,ymax,0) node[left]{$x_3$};

\foreach \x in {0.5,1,...,4.5}
{
  \draw [gridstyle] (0,0,\x) -- (xmax,0,\x);
  \draw [gridstyle] (0,0,\x) -- (0,ymax,\x);

  \draw [gridstyle] (\x,0,0) -- (\x,0,zmax);
  \draw [gridstyle] (\x,0,0) -- (\x,ymax,0);

  \draw [gridstyle] (0,\x,0) -- (0,\x,zmax);
  \draw [gridstyle] (0,\x,0) -- (xmax,\x,0);
}
\foreach \x in {1,...,4}
{
  \draw [tickstyle] (0,0,\x) -- (0,-ticklen,\x) node[below] {$\x$};

  \draw [tickstyle] (\x,0,0) -- (\x,-ticklen,0) node[below] {$\x$};

  \draw [tickstyle] (0,\x,0) -- (-ticklen,\x,0) node[left] {$\x$};
}

\fill[axisbg=green] (0,0,0) -- (0,0,zmax) -- (0,ymax,zmax) -- (0,ymax,0);
\fill[axisbg=blue]  (0,0,0) -- (xmax,0,0) -- (xmax,ymax,0) -- (0,ymax,0);
\fill[axisbg=red]   (0,0,0) -- (xmax,0,0) -- (xmax,0,zmax) -- (0,0,zmax);

\draw[arrows=blue]  (2,0,2) -- (2,2,2);
\draw[arrows=red]   (0,0,2) -- (2,0,2);
\draw[arrows=green] (0,0,0) -- (0,0,2);

\shade[ball color=yellow] (2,2,2) circle[radius=0.1];

\end{tikzpicture}
\end{center}

\end{document}