13

Is TikZ the best way of doing this do you think?

enter image description here

Any other method you can think of?

4

2 Answers 2

23
+200

If you do not want that much control and precision over and in your little pictures, you can use the following solution.

It uses

  • amstext (usually loaded by amsmath anyway) for the \text macro,
  • blkarray for the parentheses between columns (there could easily by various TikZ(mark) solutions usable here), and
  • PGF/TikZ

The TikZ picture consists of two paths for the axes and one path for the plot.

The picture’s usual coordinate system is shrinked by the factor 10. I took a rather unorthodox way for the axes and just used coordinates of the factor 1 (base unit). The actual x and the y value are computated via the x and y factor.

This way, the axes do not scale with the plot or the total TikZ picture but after all the domain setting also affect the plot. A special style my be introduced here that sets all other settings based on the domain. I have used two examples with borderline values so that either the y axis had to be extended or the whole picture has to be shrunken which probably won’t be a real use-case as this distorts any relation to the other pictures.

Be aware of a high samples value because this slows down the process very much. It may be advisavle to externalize the calculation (gnuplot) and/or use the external library of TikZ. You also may pre-calculate some values (you’ll need a table plot then) and simply change the coordinate system and/or scale the resulting picture.

Code

\documentclass{article}
\usepackage{amstext}
\usepackage{blkarray}
\usepackage{tikz}
\tikzset{
  declare function={NormDist(\xValue,\meanValue,\standardDeviation)=1/(\standardDeviation*sqrt(2*pi))*exp(-((\xValue-\meanValue)^2)/(2*\standardDeviation^2));},
}
\newcommand*{\tikzNormDist}[3][]{%
  \begin{tikzpicture}[every mini plot picture/.try,#1]
    \path[every mini plot x axis/.try] (-1,0) -- (1,0);
    \path[every mini plot y axis/.try] (0,0) -- (0,1) [mini plot y axis arrow/.try];
    \draw[every mini plot plot/.try]   plot[variable=\x] (\x,{NormDist(\x,#2,#3)});
  \end{tikzpicture}
}
\tikzset{
  every mini plot picture/.style={x=+1mm, y=+1mm, baseline=.5},
  every mini plot x axis/.style={draw,thin,x=+2mm},
  every mini plot y axis/.style={draw,thin,y=+2.2mm},
  every mini plot plot/.style={
    thick,
    red,
    smooth,
    samples=40,
    domain=-2:2,
  },
  mini plot y axis arrow/.style={
    insert path={
      [line cap=round, line join=round]+(+.25mm,+-.5mm) -- +(+0,+0) -- +(+-.25mm,+-.5mm)
    }
  }
}
\begin{document}
\[
  \begin{blockarray}{l c*2{@{\hphantom{{}+{}}}c}}
   & \text{Table} & \text{Bed} & \text{Pat} \\
  \begin{block}{l(*2{c@{{}+{}}}c)}
  \text{Table} & \tikzNormDist{0}{0.3}   & \tikzNormDist[
                                               every mini plot plot/.append style={blue!50!red,fill=blue!50!green},
                                               every mini plot y axis/.append style={y=+3.5mm}
                                           ]{-.3}{0.15}               & \tikzNormDist{-.2}{0.4} \\
  \text{Bed}   & \tikzNormDist{.2}{0.5}  & \tikzNormDist{.7} {0.7}    & \tikzNormDist{-.5}{0.7} \\
  \text{Pat}   & \tikzNormDist{-.1}{0.4} & \tikzNormDist{-.1}{1}      & \tikzNormDist[
                                                                            every mini plot plot/.append style={domain=-10:10,x=+.25mm,y=+5mm}
                                                                        ]{0}{2} \\
  \end{block}
  & {} = 1 & {} = 1 & {} = 1 \\
  \end{blockarray}
\]
\end{document}

Output

enter image description here

1
  • 1
    This is amazing! Definitely giving bounty for this when it's available! Thank you so much! :-)
    – HCAI
    Commented Jul 3, 2013 at 18:00
1

Since I am not to experienced with latex and know tikz I would use it. If you happen to be familiar with R you can combine the two (e.g.http://www.texample.net/tikz/examples/tikzdevice-demo/).

Another example what you can do with tikz regarding normal distributions is this: http://www.texample.net/tikz/examples/animated-distributions/.

I can not quite make sense of the matrix you drew up. When using a matrix node to organize multiple subpictures you might have to wrap the subfigures in a matrix like this: {\tikz{....}} (see https://tex.stackexchange.com/a/119306/19326).

You could consider using a picture for the normal distributions and use tikz overlay mode. On semi alternative would be pgfplots (which is also based on tikz, but why learn a new tool), another one would be pstricks.

2
  • PGFPlots is based on TikZ/PGF, not PSTricks. It makes the creation of plots a whole lot easier than relying only on the built-in TikZ \draw plot command, because it takes care of the scaling, the axes, the legends, the labels, basically all the things that would be very tedious to build by hand in TikZ. It also allows you to plot datafiles and create 3D plots of functions and data. If you need that kind of functionality, it makes sense to learn how to use PGFPlots (if you know how to use TikZ, it's a very small step to PGFPlots).
    – Jake
    Commented Jul 3, 2013 at 1:32
  • @Jake: point taken, I got carried away and formulated the pstricks part unclear, which I wanted to mention as a nother alternative. As for the PGFPlots part, will it be integrated into tikz (there is datavisualization in tikz development) or will it remain separate?
    – ted
    Commented Jul 3, 2013 at 6:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .