1

I have the following tikz picture but I can't figure out how to properly align the characters on the left (A,B,C,D,E). I'm pretty sure there's a better way than how I did it with the node labels. Any ideas? I keep getting lost in the pgf tikz documentation and other examples on SE don't seem to have the right solution for me...

Cheers F

\begin{tikzpicture}[scale=.75]
    \coordinate (y) at (0,6);
    \coordinate (x) at (11,0);
    \draw[<->, style=thick] (y) node[above left]{outcomes} -- (0,0) --  (x);

    \filldraw[red] (1,2) circle (5pt);
    \filldraw[red] (1,3) circle (5pt);
    \filldraw[red] (1,4) circle (5pt);

    \filldraw[blue] (2,1) circle (5pt);
    \filldraw[blue] (2,2) circle (5pt);
    \filldraw[blue] (2,3) circle (5pt);
    \filldraw[blue] (2,4) circle (5pt);

    \filldraw[red] (5,2) circle (5pt);
    \filldraw[red] (5,3) circle (5pt);
    \filldraw[red] (5,4) circle (5pt);

    \filldraw[blue] (6,2) circle (5pt);
    \filldraw[blue] (6,4) circle (5pt);

    \filldraw[red] (9,2) circle (5pt);
    \filldraw[red] (9,3) circle (5pt);
    \filldraw[red] (9,4) circle (5pt);

    \filldraw[blue] (10,3) circle (5pt);
    \filldraw[blue] (10,4) circle (5pt);
    \draw
        (0,1) node[left] {E}
        (0,2) node[left] {D}
        (0,3) node[left] {C}
        (0,4) node[left] {B}
        (0,5) node[left] {A}

        (1,0) node[below] {$\theta$}
        (2,0) node[below] {$\theta'_1$}
        (5,0) node[below] {$\theta$}
        (6,0) node[below] {$\theta'_2$}
        (9,0) node[below] {$\theta$}
        (10,0) node[below] {$\theta'_3$}
\end{tikzpicture}
2
  • There is a semicolon missing at the end of the last path before \end{tikzpicture}.
    – user194703
    Jan 7 '20 at 22:43
  • thanks, but that didn't seem to cause any problem...
    – fjungplan
    Jan 7 '20 at 22:57
1

If the question is whether you may make the code shorter and more efficient, the answer is yes.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.75,mark size=5pt]
    \coordinate (y) at (0,6);
    \coordinate (x) at (11,0);
    \draw[stealth-stealth, style=thick] (y) node[above left]{outcomes} -- (0,0) --  (x);
    \path[red] plot[only marks,mark=*] coordinates {
        (1,2) (1,3) (1,4) (5,2) (5,3) (5,4) (9,2) (9,3) (9,4)};
    \path[blue] plot[only marks,mark=*] coordinates {
        (2,1) (2,2) (2,3) (2,4) (6,2) (6,4) (10,3) (10,4)};
    \path foreach \X [count=\Y] in {A,...,E}
     {(0,6-\Y) node[left]{\X}}
     foreach \X in {1,2,3}
     {(4*\X-3,0) node[below] {$\theta$}
      (4*\X-2,0) node[below] {$\theta'_\X$}};
\end{tikzpicture}
\end{document}

enter image description here

Obviously one may tune things (arrows.meta etc.), but I feel that you are really looking for pgfplots.

Here is my comment spelled out.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.75,mark size=5pt]
    \coordinate (y) at (0,6);
    \coordinate (x) at (11,0);
    \draw[stealth-stealth, style=thick] (y) node[above left]{outcomes} -- (0,0) --  (x);
    \path[red] plot[only marks,mark=*] coordinates {
        (1,2) (1,3) (1,4) (5,2) (5,3) (5,4) (9,2) (9,3) (9,4)};
    \path[blue] plot[only marks,mark=*] coordinates {
        (2,1) (2,2) (2,3) (2,4) (6,2) (6,4) (10,3) (10,4)};
    \path[nodes={text height=1.1em,text depth=0.25ex}] foreach \X [count=\Y] in {A,...,E}
     {(-2em,6-\Y) node[right,align=left]{\X}}
     foreach \X in {1,2,3}
     {(4*\X-3,0) node[below] {$\theta$}
      (4*\X-2,0) node[below] {$\theta'_\X$}};
\end{tikzpicture}
\end{document}

enter image description here

3
  • Thanks heaps! This is one of my first tikZ pictures so unfortunately the code is far from being optimal. But actually your example is showing the same issue that I'm facing: the labels on the left (A,B,C,D,E) don't look perfectly left aligned to me... Any idea how to fix that? I tried pgfplots first but I neither found good examples to start working from nor did I find what I need in the documentation (I'm sure it's somewhere there but I don't know exactly which terms to look for or I just don't understand its meaining)
    – fjungplan
    Jan 7 '20 at 22:59
  • @fjungplan No, they are not left aligned because their anchor is east. How precisely should they be aligned? Does \path[nodes={text height=1.1em,text depth=0.25ex}] foreach \X [count=\Y] in {A,...,E} {(-2em,6-\Y) node[right,align=left]{\X}} foreach \X in {1,2,3} {(4*\X-3,0) node[below] {$\theta$} (4*\X-2,0) node[below] {$\theta'_\X$}}; come closer?
    – user194703
    Jan 7 '20 at 23:12
  • @schrödingers-cat thanks, I'll check that later after work!
    – fjungplan
    Jan 8 '20 at 10:16

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.