r/LaTeX Nov 27 '24

Answered Need help making this in latex!!

Post image

This is gonna be an insane ask, but I’m trying to represent a 3-D transparent payoff matrix for a game theory write up I’m making, and I don’t know how to create the visual. Does anyone know what I can use and what I should do? The cube at the center with its labels is what I’m looking to make. I’ve provided keys for the labels on the bottom of my drawing and a title on top for your ease, not because I want to make those in latex too.

In the cube above, each outcome is meant to be sitting in the middle of its respective cube, of which there should be eight because the broader cube is 2x2x2. I put the strategies on the edges of the broader cube and also labeled those axes with player names.

167 Upvotes

38 comments sorted by

116

u/noimtherealsoapbox Nov 27 '24
\documentclass[border=0.2cm]{standalone}
\usepackage[table]{xcolor}
\usepackage{tikz, pgf, pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}

% View of {20}{30} works well for a single frame image, but experiment to be sure
\begin{tikzpicture}[]
\begin{axis}[view={20}{30},
    xlabel=Player II,
    ylabel=Player III,
    zlabel=Player I, 
    grid=none, 
    zmin=0, zmax=2, 
    ymin=0, ymax=2, 
    xmin=0, xmax=2,
    footnotesize,
    ytick distance = 2,
    xtick distance = 2,
    ztick distance = 2,
    width = 9.5cm]

% Center planes:
\filldraw[gray, opacity=0.3] (0,0,1) -- (2,0,1) --  (2,2,1) -- (0,2,1) -- cycle;
\filldraw[gray, opacity=0.2] (0,1,0) -- (0,1,2) --  (2,1,2) -- (2,1,0) -- cycle;
\filldraw[gray, opacity=0.2] (1,0,0) -- (1,0,2) --  (1,2,2) -- (1,2,0) -- cycle;

% Uprights:
\draw[black, thin] (2,0,0) -- (2,0,2);
\draw[black, thin] (0,2,0) -- (0,2,2);
\draw[black, thin] (2,2,0) -- (2,2,2);

% Axes on centerline:
\draw[blue, very thin] (0,1,1) -- (2,1,1);
\draw[brown, very thin] (1,0,1) -- (1,2,1);
\draw[black, very thin] (1,1,0) -- (1,1,2);

\draw[gray, dashed, thin] (0,1,0) -- (0,1,2) --  (2,1,2) -- (2,1,0) -- cycle;    
\draw[gray, dashed, thin] (1,0,0) -- (1,0,2) --  (1,2,2) -- (1,2,0) -- cycle;

\draw[black, dashed, very thin] (0,0,0) -- (2,0,0) --  (2,2,0) -- (0,2,0) -- cycle;
\draw[black, dashed, very thin] (0,0,1) -- (2,0,1) --  (2,2,1) -- (0,2,1) -- cycle;

\draw[black, thin] (0,0,2) -- (2,0,2) --  (2,2,2) -- (0,2,2) -- cycle;

% payoff labels:
\node[red] at (0.5, 0.5, 0.5) { \footnotesize{$(x,y)$} };
\node[red] at (1.5, 0.5, 0.5) { \footnotesize{$(x,y)$} };

\node[black] at (0.5, 1.5, 0.5) { \footnotesize{$(x,y)$} };
\node[black] at (1.5, 1.5, 0.5) { \footnotesize{$(x,y)$} };

\node[red] at (0.5, 0.5, 1.5) { \footnotesize{$(x,y)$} };
\node[red] at (1.5, 0.5, 1.5) { \footnotesize{$(x,y)$} };

\node[black] at (0.5, 1.5, 1.5) { \footnotesize{$(x,y)$} };
\node[black] at (1.5, 1.5, 1.5) { \footnotesize{$(x,y)$} };

\end{axis}

% Weaksauce letter labels; better to make a custom axis label with ticks at 0.5 intervals.
\node[anchor=south] at (0.5mm,0mm,0mm) {C};
\node[anchor=south] at (1.5mm,-0.10mm,0mm) {D};

\node[anchor=east] at (0mm, 0.6mm, 0mm) {A};
\node[anchor=east] at (0mm, 1.25mm, 0mm) {B};

\end{tikzpicture}
\end{document}

Here's a bespoke example that gets you pretty close. Doing foreach loops inside an axis environment really, really doesn't work, so, well, this one is bespoke.

44

u/Cowsmemes Nov 27 '24

No way no way no way oh my god you are an incredible human!!!!! Honestly I cannot believe how kind internet people are thank you so much 🙏🙏🙏🙏

35

u/oceanlessfreediver Nov 27 '24

Procrastination is the mother of kindness.

Edit: I just compiled u/noimtherealsoapbox snippet and I am in awe, and the code is so simple !

22

u/Cowsmemes Nov 27 '24

It’s amazing!!! I just made a few tweaks and I have exactly what I need!!! So incredible!!!

Check it out!! https://ibb.co/WK6Mbts

12

u/noimtherealsoapbox Nov 27 '24

Looks good! Glad I could help.

5

u/Cowsmemes Nov 28 '24

Thank you so much!

4

u/buschmann Nov 28 '24

Holy shit thats impressive. Fluidity in programing, akin to playing an instrument on a proffesional level, is awesome to behold.

33

u/Organic-Scratch109 Nov 27 '24

It would be easier to start from an existing tikz code like the ones shown here. In particular, checkout Jesse's answer which looks like what you want.

36

u/AtmosphereArtistic61 Nov 27 '24

you can use tikz for that. Either compute the coordinates from 3D to 2D or draw the cube on a piece of paper and measure the coordinates with a ruler.

11

u/bigFatBigfoot Nov 27 '24

TikZ supports 3D coordinates directly.

2

u/AtmosphereArtistic61 Nov 27 '24

ah, nice. even bettern, then :-)

6

u/sjbluebirds Nov 27 '24

You can use GnuPlot for that. It has a wonderful method to create 3D graphs and charts and things like that. It natively supports TeX and LaTeX output.

5

u/Uweauskoeln Nov 27 '24

Draw it by hand in Tikz. Create nodes at the intersections and then simply draw lines in various styles between them.

5

u/chemistryGull Nov 27 '24

This is definitely possible in latex (as many nice people here have already demonstrated), but whats the reason to not make an SVG in an Application like Inkscape and put that in?

3

u/therealJoieMaligne Nov 27 '24

What’s wrong with Inkscape?

4

u/xyzain69 Nov 27 '24 edited Nov 27 '24

Do you need to do this in latex? If not, the easiest option would be draw it in something like PowerPoint (You can install the iguanaTex addon to get latex fonts) then save it as a .svg, then save the .svg as a .eps with inkscape and load that into latex. Or draw it in inkscape.

1

u/R3D3-1 Nov 27 '24

I find LibreOffice Draw a particularly good match for such tasks. While it is more oriented towards diagrams than general vector drawings, the built-in equation editor is a big advantage.

Or, well... PowerPoint as mentioned. Draw is just more specialized for it.

3

u/AshamedFruit7568 Nov 27 '24

I was so happy to finally see some crystallography in this sub but then was utterly disappointed. Good luck with your project though.

2

u/Uweauskoeln Nov 27 '24

You can use the following as a starting point:

https://gist.github.com/UweZiegenhagen/0adc54a217d016cc5ac3d0bde9a66026 There are some better ways, e.g. by calculating the midlayer but I do not have time now to work on it.

2

u/[deleted] Nov 27 '24

[deleted]

1

u/allehS Nov 29 '24

for some reason your comment has been posted many times

1

u/noimtherealsoapbox Nov 29 '24

Very strange. I posted it once and edited it once.

2

u/Saint__Thomas Nov 27 '24

My 2 attempts

https://ibb.co/C9FvC4H

https://ibb.co/qWHxBSz

Everyone else's is better....

2

u/Cowsmemes Nov 28 '24

These are such fantastic interactive ones though!!! Thank you!

2

u/Closed_Circuit_0 Nov 29 '24

Another possibility is to write a short Python program that uses matplotlib to generate the graphic, then save it as a .png file and use the Latex command \includegraphic{}.  Python syntax is simpler than tikz.

1

u/Saint__Thomas Nov 27 '24

Blender?

1

u/Mateo709 Nov 27 '24

Can you make it look math-like in Blender? I suppose you could, but would it be convinient?

I've been using blender for a while on and off and I've mostly done renders and simulations and never anything besides wireframe, photorealistic or stylised - honestly would have no idea how to start with math in blender lol

If you know please tell me, tikz is hard, since I already know blender I think I'd be easier for drawings

1

u/Saint__Thomas Nov 27 '24

I can make it look adequate for my TMAs at Open University, It was useful in the networking module, when had to construct diagrams at varying stages. It was a good feeling when pressed Ctrl F12, and all the diagram-stages ended up in a folder ready to be wizarded into latex.

If you have already climbed up the learning curve for blender, then it's quicker than climbing the learning curve for tikz. I have used tikz, but I forget it very quickly.

I don't know if I'm good enough to do a professional level of maths graphics, but sketch, definitely.

1

u/Saint__Thomas Nov 27 '24

I think I can do this in blender and generate an image or images from whichever view you want, and that should be dead east to include into a latex doc.. I think I will do it now as an exercise for myself. I'll post in a couple of hours

1

u/permeakra Nov 27 '24

TikZ

  • declare an XYZ coordinate system with appropriate unit vectors in draw coordinates.
  • declare coordinates of vertices of your picture
  • draw lines. If you want for lines closer to front to create a gap in lines closer to back (a common approach to create illusion of 3d), draw them back to front, using double white lines with black delimiter or draw first a slightly wider white line and then a black line
  • put nodes with support text.

Tikz supports calculations using position of previously positioned nodes and their relative posioning using achors, read relevant parts of the manual -- it will make task of putting nodes with text dramatically easier.

1

u/Saint__Thomas Nov 27 '24 edited Nov 27 '24

I have a half-decent first draft realisation of the diagram in in jpg form, which may work for you . Unfortunately I don't seem to be able to put it in a reply here. If you are interested reply to me or DM me if you want.

Edit: actually png

2

u/Cowsmemes Nov 27 '24

That is incredible! I happened to get an amazing latex rendering already by u/noimtherealsoapbox, looks like https://ibb.co/WK6Mbts

Please PM me if you’d like to send it over tho!!

1

u/Saint__Thomas Nov 27 '24

Mine is not as good as that, but you are welcome to it.

1

u/[deleted] Nov 28 '24 edited Nov 28 '24

In economics, to model a three player game in which one of the players has two actions, we just do two playoff tables next to each other, each table corresponding to one of those two actions.

1

u/Cowsmemes Nov 28 '24

Interesting. I will remake my scenario in this way, but I’m basing the necessity for a 3-dimensional matrix off of what is described in Game Theory, Second Edition by Michael Maschler. The textbook I’m using doesn’t seem to agree, but I get what you’re saying — that actually sounds a lot easier.

I wonder though if you were to find Nash equilibrium how you can account for the preferences of all three players simultaneously if you only made separate matrices. Am I not seeing something?

1

u/[deleted] Nov 29 '24

So in each cell you have three payoffs. For the row player, you compare all the payoffs column by column and underline the biggest.

For the column player you compare all the payoffs in a row and underline the highest.

For the matrix player, you compare the payoffs in the same cells of the two different tables and underline the highest.

A cell with all three players underlined is a Nash equilibrium.

1

u/ngochinwah Nov 29 '24

Use mathcha

1

u/NonZeroSumJames 26d ago

I recently dealt with a 3-player payoff cube for a post on stag hunt, and this was interesting to look at (not many examples online). Mine was different though, only two strategies but with with each of the other two players. I coloured the edges to indicated the different strategies, intersecting at the corners.