10

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}
  • Welcome to TeX.Stackexchange! – user36296 May 11 '18 at 9:06
  • I believe you'd learn a lot from this question and its answers. The problem is that you are loading pgfplots but not using its grids. – marmot May 11 '18 at 13:56
11

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}
9

A quick solution:

\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/\zc in {2.6/1,5.2/2,7.8/3,10.4/4}{
\draw[shift={(0,0,\z)}, ultra thick] (0pt,0pt,0pt) -- (0pt,-0.21pt,0pt)node[below]{\zc};
\draw[gray!60!white, thick](0,0,\z)--++(0:10);
\draw[gray!60!white, thick](0,0,\z)--++(90:10);}
\foreach \x/\xc in {2/1,4/2,6/3,8/4}{
\draw[shift={(\x,0)}, ultra thick] (0pt,0pt) -- (0pt,-6pt)node[below]{\xc};
\draw[gray!60!white, thick](\x,0)--++(0:10);
\draw[gray!60!white, thick](\x,0)--++(90:10);
\draw[gray!60!white, thick](\x,0)--++(-135:7);}
\foreach \y/\yc in {2/1,4/2,6/3,8/4}{
\draw[shift={(0,\y)}, ultra thick] (0pt,0pt) -- (-6pt,0pt)node[left]{\yc};
\draw[gray!60!white, thick](0,\y)--++(0:10);
\draw[gray!60!white, thick](0,\y)--++(-135:7);}
\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}

enter image description here

5

As you are loading pgfplots, why not using it? It does all the grids with a simple option.

\documentclass{scrartcl}

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

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[x={(10,0)},y={(0,10)},z={({-10/sqrt(8)},{-10/sqrt(8)})},
grid = both,minor tick num=4,xmin=0,xmax=9.9,ymin=0,ymax=9.9,zmin=0,zmax=12.7,
ticks=none,clip=false,tick style={opacity=0}]
\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$};
\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);

\addplot3[->,no marks,blue,ultra thick] coordinates {(4,0,5.2) (4,4,5.2)};
\addplot3[->,no marks,red,ultra thick] coordinates {(0,0,5.2) (4,0,5.2)};
\addplot3[->,no marks,green,ultra thick] coordinates {(0,0,0) (0,0,5.2)};
\shade[ball color=yellow] (4,4,5.2) circle (0.2);
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

EDIT: Fixed the z units.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.