Is TikZ the best way of doing this do you think?
Any other method you can think of?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityIf 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), andThe 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.
\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}
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.
\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).
\matrix
very easily. Or you use a math-modealigned
environment and place little TikZ images in there.