# tikzpictures positioning

I am having trouble trying to position tikzpictures in their correct position... I want to place the 3 plots with the green filling in a single line above (with the alpha/2 right below), and the 3 plots with the yellow filling in a single line below (with the alpha/2 right below)... how could I specify here a new line?? I have tried using \nodes but for some reason it does not work.

There is something I am missing here, since I specify the width of the minipages to be \linewidth, and the paperwidth of the document is slightly more than the width of 3 plots in line.

The following MWE produces this figure:

However, I would like that it produced a picture similar to this one (which I have made manually):

The code I have so far is the following:

\documentclass{standalone}

\usepackage[paperwidth=32cm,paperheight=15cm]{geometry}

\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}

{\large
\begin{minipage}{\linewidth}
\textcolor{green!70!black}{Tissue-specific expression}\\
\begin{tikzpicture}
\begin{axis}[
no markers, domain=0:12, samples=100,
axis lines*=left, xlabel=\empty, ylabel=\empty,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=9cm,
xtick={2,8}, ytick=\empty,
xticklabels={{\footnotesize $\mu$1},{\footnotesize $\mu$2}},
enlargelimits=false, clip=false, axis on top]
\closedcycle;
\closedcycle;
\node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
\node at (axis cs: 8,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
\end{axis}
\begin{tikzpicture}
\begin{axis}[
no markers, domain=0:25, samples=100,
axis lines*=left, xlabel=\empty, ylabel=\empty,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=9cm,
xtick={2,8,19}, ytick=\empty,
xticklabels={{\footnotesize $\mu$1},{\footnotesize $\mu$2},{\footnotesize $\mu$3}},
enlargelimits=false, clip=false, axis on top]
\closedcycle;
\closedcycle;
\closedcycle;
\closedcycle;
\node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
\node at (axis cs: 8,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
\node at (axis cs: 19,0.04) [font=\footnotesize, inner sep=1pt, above] {$\sigma 3$};
\end{axis}
\begin{tikzpicture}
\begin{axis}[
no markers, domain=0:25, samples=100,
axis lines*=left, xlabel=\empty, ylabel=\empty,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=9cm,
xtick={2,5,19}, ytick=\empty,
xticklabels={{\footnotesize $\mu$1},{\footnotesize $\mu$2},{\footnotesize $\mu$3}},
enlargelimits=false, clip=false, axis on top]
\closedcycle;
\closedcycle;
\closedcycle;
\closedcycle;
\node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
\node at (axis cs: 5,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
\node at (axis cs: 19,0.04) [font=\footnotesize, inner sep=1pt, above] {$\sigma 3$};
\end{axis}
\end{tikzpicture}
{\small {$\alpha$}/2=0.025}
\end{minipage}\hfill
\begin{minipage}{\linewidth}
\textcolor{yellow!60!black}{Ubiquitous expression}\\
\begin{tikzpicture}
\begin{axis}[
no markers, domain=0:10, samples=100,
axis lines*=left, xlabel=\empty, ylabel=\empty,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=9cm,
xtick=5, xticklabels={\footnotesize $\mu$1},
ytick=\empty,
enlargelimits=false, clip=false, axis on top]
\closedcycle;
\closedcycle;
\node at (axis cs: 5,0.1) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
\end{axis}
\begin{tikzpicture}
\begin{axis}[
no markers, domain=0:10, samples=100,
axis lines*=left, xlabel=\empty, ylabel=\empty,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=9cm,
xtick={3,6}, ytick=\empty,
xticklabels={{\footnotesize $\mu$1},{\footnotesize $\mu$2}},
enlargelimits=false, clip=false, axis on top]
\closedcycle;
\closedcycle;
\node at (axis cs: 3,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
\node at (axis cs: 6,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
\end{axis}
\begin{tikzpicture}
\begin{axis}[
no markers, domain=0:15, samples=100,
axis lines*=left, xlabel=\empty, ylabel=\empty,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=9cm,
xtick={2,5,10}, ytick=\empty,
xticklabels={{\footnotesize $\mu$1},{\footnotesize $\mu$2},{\footnotesize $\mu$3}},
enlargelimits=false, clip=false, axis on top]
\closedcycle;
\closedcycle;
\closedcycle;
\closedcycle;
\node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
\node at (axis cs: 5,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
\node at (axis cs: 10,0.04) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
\end{axis}
\end{tikzpicture}
{\scriptsize {$\alpha$}/2=0.025}
\end{minipage}%
}
\end{document}


Once this issue is solved, I would like to convert the resulting pdf with a proper density setting, which I have no idea how... but this is secondary, as I can always print the screen or something... Thanks!

-
How should LaTeX how big a pixel is? This depends on the density, the dpi (dots per inch) settings when you convert the document to a raster picture. – Qrrbrbirlbel Sep 25 '13 at 16:04
So there is no way to specify the size of the document? – DaniCee Sep 25 '13 at 16:49
You can specify the size in length units (the TeX usuals: pt, cm, in, mm, bp, sp) and then convert the resulting PDF with a proper density setting. By the way, you better split up your question in two: One for the conversion of a *TeX output to certain-sized PNG (or whatever) and one for the pgfplots stuff. — What happened to Create pngs specifying dimensions? – Qrrbrbirlbel Sep 25 '13 at 16:51
Could you explain step by step how to "convert the resulting pdf with a proper density setting"? Also I'd appreciate if anyone knows how to specify a new line to have the plots arranged as described above? Thanks – DaniCee Sep 26 '13 at 14:21
nobody knows? I was hoping placing tikzpictures and creating a png out of them would be a really trivial thing... – DaniCee Sep 27 '13 at 13:56

There are two parts to this answer. The first one is about using groupplots tp organise the plots in a 3x2 grid, the second about a way of converting to PNG.

# groupplots

You could use the groupplots library to arrange the plots. See section 5.5 Grouping plots in the manual.

groupplots is great for cases where you want to organise several plots in a grid, such as here. You use a groupplot environment instead of axis, and start a new axis with \nextgroupplot. In the options to the groupplot enviroment you can specify settings that should be the same for all the sub axes, such as width/height, style of axis lines etc.

With group style={group size=3 by 2} you set the number of columns in the grid to 3, and the number of rows to 2. In the group style one can also define the distance between the plots, with horizontal sep and vertical sep.

I've tidied up the code a little bit. Other customisations could be done, for example one could define a \newcommand to draw the arrow with the sigma on top, but I haven't done that. What I have done:

• Defined four new styles:

• sigmalabel - for the nodes with $\sigma 1$
• tissue- for the \closedcycle plots in the first three subplots, defining color and draw=none
• ubiq - similar to tissue, for the last three
• plotline - just color of the plotted lines
• Moved all common settings to the groupplot environment, instead of repeating it for each \nextgroupplot.
• Instead of adding \footnotesize in each xtick, I change the x tick label style.
• Instead of having the text outside the tikzpicture, I add them as nodes placed relative to the axes. By adding group name=some string to the group style, each subaxis will become a named node, so some string c1r2 is the axis in the first column and second row of the grid. Further, some string c1r2.north west will be the top right corner of this. The text is placed relative to such coordinates.

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\pgfplotsset{compat=1.9}

\tikzset{
sigmalabel/.style={font=\footnotesize, inner sep=1pt, above},
tissue/.style={fill=green!70!black, draw=none},
ubiq/.style={fill=yellow!60!black, draw=none},
plotline/.style={cyan!50!black}
}

\begin{document}

\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=3 by 2,
group name=mydist,
vertical sep=2cm,
horizontal sep=10pt},
width=5cm,
height=3cm,
no markers,
samples=100,
axis lines*=left,
ytick=\empty,
enlargelimits=false,
clip=false,
axis on top,
x tick label style={font=\footnotesize}]

% start of tissue-specific plots
\nextgroupplot[
domain=0:12,
xtick={2,8},
xticklabels={$\mu 1$,$\mu 2$}
]

\closedcycle;
\closedcycle;

\node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
\node at (axis cs: 8,0.12) [sigmalabel] {$\sigma 2$};

\nextgroupplot[
domain=0:25,
xtick={2,8,19},
xticklabels={$\mu 1$,$\mu 2$,$\mu 3$}
]

\closedcycle;
\closedcycle;
\closedcycle;
\closedcycle;

\node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
\node at (axis cs: 8,0.12) [sigmalabel] {$\sigma 2$};
\node at (axis cs: 19,0.04) [sigmalabel] {$\sigma 3$};

\nextgroupplot[
domain=0:25,
xtick={2,5,19},
xticklabels={$\mu 1$,$\mu 2$,$\mu 3$}
]

\closedcycle;
\closedcycle;
\closedcycle;
\closedcycle;

\node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
\node at (axis cs: 5,0.12) [sigmalabel] {$\sigma 2$};
\node at (axis cs: 19,0.04) [sigmalabel] {$\sigma 3$};

% start of ubiquitous plots
\nextgroupplot[
domain=0:10,
xtick=5,
xticklabels={$\mu 1$}
]

\closedcycle;
\closedcycle;

\node at (axis cs: 5,0.1) [sigmalabel] {$\sigma 1$};

\nextgroupplot[
domain=0:10,
xtick={3,6},
xticklabels={$\mu 1$,$\mu 2$}
]

\closedcycle;
\closedcycle;

\node at (axis cs: 3,0.2) [sigmalabel] {$\sigma 1$};
\node at (axis cs: 6,0.12) [sigmalabel] {$\sigma 2$};

\nextgroupplot[
domain=0:15,
xtick={2,5,10},
xticklabels={$\mu 1$,$\mu 2$,$\mu 3$}
]

\closedcycle;
\closedcycle;
\closedcycle;
\closedcycle;

\node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
\node at (axis cs: 5,0.12) [sigmalabel] {$\sigma 2$};
\node at (axis cs: 10,0.04) [sigmalabel] {$\sigma 1$};

\end{groupplot}

\node at (mydist c1r1.north west) [above right,green!70!black] {Tissue-specific expression};
\node at (mydist c1r1.south west) [below right,yshift=-2ex,font=\footnotesize] {$\alpha/2=0.025$};

\node at (mydist c1r2.north west) [above right,green!70!black] {Ubiquitous expression};
\node at (mydist c1r2.south west) [below right,yshift=-2ex,font=\footnotesize] {$\alpha/2=0.025$};

\end{tikzpicture}

\end{document}


# Converting to PNG

The standalone class allows you to have your tikzpictures converted to PNG directly. This requires that ImageMagick is installed, see the manual for details. Start by removing everything outside the tikzpicture environments from the document environment, and adding e.g. tikz,convert={density=150} to the options of the class. When compiling you have to enable shell-escape. The code would look something like

\documentclass[tikz,convert]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
...
\end{tikzpicture}
\begin{tikzpicture}
...
\end{tikzpicture}
\end{document}


Each tikzpicture` will be given a separate page in the PDF, and a separate PNG is created.

-