4

Can someone please help me with a simple LaTeX code to draw something like the attached picture? 3D Matrix table

  • Is the misalignment of the face containing "Item_1", "Item_2" intentional and should be reproduced? – Gonzalo Medina May 13 '14 at 23:14
  • No, it's not intentional, I'd be glad if the shape is more regular. Thanks. – hlosukwakha May 14 '14 at 7:11
9

A possible solution based on http://www.texample.net/tikz/examples/sudoku-3d-cube/ :

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning}

\definecolor{colortop}{RGB}{184,223,155}
\definecolor{colorside}{RGB}{0,209,54}

\DeclareMathOperator{\Att}{Att}
\DeclareMathOperator{\Item}{Item}

\begin{document}

\pagestyle{empty}
\begin{tikzpicture}[every node/.style={minimum size=1cm,font=\scriptsize},on grid]
\begin{scope}[every node/.append style={yslant=-0.5,rotate=90},yslant=-0.5]
  \shade[right color=colorside!30, left color=colorside!50] (-1,0) rectangle +(4,3);
  \node at (-0.5,2.25) {};
  \node at (0.5,2.25) {$\Att_1$};
  \node at (1.5,2.25) {$\Att_2$};
  \node at (2.5,2.25) {$\Att_3$};
  \node at (-0.5,0.75) {User};
  \node at (0.5,0.75) {$1$};
  \node at (1.5,0.75) {$0$};
  \node at (2.5,0.75) {$0$};
  \draw (-1,0) grid[ystep=1.5] (3,3);
\end{scope}
\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]
  \shade[right color=colorside!70,left color=colorside!10] (3,-3) rectangle +(5,3);
  \node at (3.5,-0.5) {};
  \node at (4.5,-0.5) {$\Att_1$};
  \node at (5.5,-0.5) {$\Att_2$};
  \node at (6.5,-0.5) {$\Att_3$};
  \node at (7.5,-0.5) {$\Att_4$};
  \node at (3.5,-1.5) {$\Item_1$};
  \node at (4.5,-1.5) {$0$};
  \node at (5.5,-1.5) {$1$};
  \node at (6.5,-1.5) {$1$};
  \node at (7.5,-1.5) {$1$};
  \node at (3.5,-2.5) {$\Item_2$};
  \node at (4.5,-2.5) {$0$};
  \node at (5.5,-2.5) {$0$};
  \node at (6.5,-2.5) {$1$};
  \node at (7.5,-2.5) {$0$};
  \draw (3,-3) grid (8,0);
\end{scope}
\begin{scope}[every node/.append style={
    yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
  ]
  \shade[bottom color=colortop!10, top color=colortop!80] (8,4) rectangle +(-5,-4);
  \node[font=\scriptsize\color{red},rotate=-90] at (5.5,2) {User--item feature matrix};
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

I edited this answer with the owner's agreement.

  • I was doing kind of the same, so no point in giving a really similar answer, but I'll leave in pastebin my code, in case you want to incorporate some of the modifications I made for my answer. – Gonzalo Medina May 13 '14 at 23:48
  • I can't access to pastebin.com from here. Please upload to another site if possible. – ferahfeza May 14 '14 at 0:16
  • Any site you know? The only one I've used for pasting code is patebin. – Gonzalo Medina May 14 '14 at 0:17
  • Do you use the chat room? I could leave it there. – Gonzalo Medina May 14 '14 at 0:19
  • I created a chat room here and left the code there; see chat.stackexchange.com/transcript/message/15512343#15512343 – Gonzalo Medina May 14 '14 at 0:32
5

Here is a pst-3dplot implementation:

enter image description here

\documentclass{article}
\usepackage{pst-3dplot,xcolor,multido,graphicx}

\newcommand{\clap}[1]{\makebox[0pt]{\footnotesize #1}}
\begin{document}

\begin{pspicture}(-4,-4)(4,4)
  % Draw box shape + colour
  \psset{linewidth = 0.5pt, linecolor = black!30, fillstyle = solid, unit = 1.2, Alpha = 50, Beta = 30}
  \pstThreeDSquare[plane = xy, fillcolor = green!65!white](0,0,3)(5,0,0)(0,5,0)
  \pstThreeDSquare[plane = xz, fillcolor = red!65!white](0,5,0)(5,0,0)(0,0,3)
  \pstThreeDSquare[plane = yz, fillcolor = blue!65!white](5,0,0)(0,5,0)(0,0,3)

  % Draw on box shape
  \pstThreeDLine(5,0,1.5)(5,5,1.5)
  \multido{\rY=1.25+1.25}{3}{\pstThreeDLine(5,\rY,0)(5,\rY,3)}
  \multido{\iZ=1+1}{2}{\pstThreeDLine(5,5,\iZ)(0,5,\iZ)}
  \multido{\iX=1+1}{4}{\pstThreeDLine(\iX,5,0)(\iX,5,3)}

  % Annotate the faces
  \psset{planecorr = normal, plane = yz, pOrigin = c}
  \pstPlanePut(5,0.625,0.75){\clap{\texttt{User}}}
  \pstPlanePut(5,1.875,0.75){\clap{0}}\pstPlanePut(5,1.875,2.25){\clap{\texttt{Att\_1}}}
  \pstPlanePut(5,3.125,0.75){\clap{1}}\pstPlanePut(5,3.125,2.25){\clap{\texttt{Att\_2}}}
  \pstPlanePut(5,4.375,0.75){\clap{1}}\pstPlanePut(5,4.375,2.25){\clap{\texttt{Att\_3}}}

  \psset{plane = xz}
  \pstPlanePut(4.5,5,0.5){\clap{\texttt{Item\_2}}}
    \pstPlanePut(3.5,5,0.5){\clap{0}}
    \pstPlanePut(2.5,5,0.5){\clap{0}}
    \pstPlanePut(1.5,5,0.5){\clap{1}}
    \pstPlanePut(0.5,5,0.5){\clap{1}}
  \pstPlanePut(4.5,5,1.5){\clap{\texttt{Item\_1}}}
    \pstPlanePut(3.5,5,1.5){\clap{0}}
    \pstPlanePut(2.5,5,1.5){\clap{1}}
    \pstPlanePut(1.5,5,1.5){\clap{1}}
    \pstPlanePut(0.5,5,1.5){\clap{0}}
  %   
    \pstPlanePut(3.5,5,2.5){\clap{\texttt{Att\_1}}}
    \pstPlanePut(2.5,5,2.5){\clap{\texttt{Att\_2}}}
    \pstPlanePut(1.5,5,2.5){\clap{\texttt{Att\_3}}}
    \pstPlanePut(0.5,5,2.5){\clap{\texttt{Att\_4}}}

  \psset{plane = xy}
  \pstPlanePut(2.5,2.5,3){\clap{\rotatebox[origin=c]{-45}{\normalsize User-item feature matrix}}}
\end{pspicture}

\end{document}

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.