Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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: enter image description here

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

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]
            \addplot [fill=green!70!black, draw=none, domain=2.75:3.65] {gauss(2,0.5)}
            \closedcycle;
            \addplot [fill=green!70!black, draw=none, domain=4.9:6.5] {gauss(8,1)}
            \closedcycle;
            \addplot [cyan!50!black] {gauss(2,0.5)};
            \addplot [cyan!50!black] {gauss(8,1)};
            \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
            \node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
            \addplot[<->] coordinates {(6.5,0.12) (9.5,0.12)};
            \node at (axis cs: 8,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
            \end{axis}
        \end{tikzpicture}\quad%
        \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]
            \addplot [fill=green!70!black, draw=none, domain=2.75:3.65] {gauss(2,0.5)}
            \closedcycle;
            \addplot [fill=green!70!black, draw=none, domain=4.9:6.5] {gauss(8,1)}
            \closedcycle;
            \addplot [fill=green!70!black, draw=none, domain=9.5:11.1] {gauss(8,1)}
            \closedcycle;
            \addplot [fill=green!70!black, draw=none, domain=13:16] {gauss(19,2)}
            \closedcycle;
            \addplot [cyan!50!black] {gauss(2,0.5)};
            \addplot [cyan!50!black] {gauss(8,1)};
            \addplot [cyan!50!black] {gauss(19,2)};
            \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
            \node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
            \addplot[<->] coordinates {(6.5,0.12) (9.5,0.12)};
            \node at (axis cs: 8,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
            \addplot[<->] coordinates {(16,0.04) (22,0.04)};
            \node at (axis cs: 19,0.04) [font=\footnotesize, inner sep=1pt, above] {$\sigma 3$};
            \end{axis}
        \end{tikzpicture}\quad%
        \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]
            \addplot [fill=green!70!black, draw=none, domain=2.75:3.65] {gauss(2,0.5)}
            \closedcycle;
            \addplot [fill=green!70!black, draw=none, domain=2:3.5] {gauss(5,1)}
            \closedcycle;
            \addplot [fill=green!70!black, draw=none, domain=6.5:8] {gauss(5,1)}
            \closedcycle;
            \addplot [fill=green!70!black, draw=none, domain=13:16] {gauss(19,2)}
            \closedcycle;
            \addplot [cyan!50!black] {gauss(2,0.5)};
            \addplot [cyan!50!black] {gauss(5,1)};
            \addplot [cyan!50!black] {gauss(19,2)};
            \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
            \node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
            \addplot[<->] coordinates {(3.5,0.12) (6.5,0.12)};
            \node at (axis cs: 5,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
            \addplot[<->] coordinates {(16,0.04) (22,0.04)};
            \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]
            \addplot [fill=yellow!60!black, draw=none, domain=1.5:3.5] {gauss(5,1)}
            \closedcycle;
            \addplot [fill=yellow!60!black, draw=none, domain=6.5:8.5] {gauss(5,1)}
            \closedcycle;
            \addplot [cyan!50!black] {gauss(5,1)};
            \addplot[<->] coordinates {(3.5,0.1) (6.5,0.1)};
            \node at (axis cs: 5,0.1) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
            \end{axis}
        \end{tikzpicture}\quad%
        \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]
            \addplot [fill=yellow!60!black, draw=none, domain=3.75:4.65] {gauss(3,0.5)}
            \closedcycle;
            \addplot [fill=yellow!60!black, draw=none, domain=2.5:4.5] {gauss(6,1)}
            \closedcycle;
            \addplot [cyan!50!black] {gauss(3,0.5)};
            \addplot [cyan!50!black] {gauss(6,1)};
            \addplot[<->] coordinates {(2.25,0.2) (3.75,0.2)};
            \node at (axis cs: 3,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
            \addplot[<->] coordinates {(4.5,0.12) (7.5,0.12)};
            \node at (axis cs: 6,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
            \end{axis}
        \end{tikzpicture}\quad%
        \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]
            \addplot [fill=yellow!60!black, draw=none, domain=2.75:3.65] {gauss(2,0.5)}
            \closedcycle;
            \addplot [fill=yellow!60!black, draw=none, domain=2:3.5] {gauss(5,1)}
            \closedcycle;
            \addplot [fill=yellow!60!black, draw=none, domain=6.5:8] {gauss(5,1)}
            \closedcycle;
            \addplot [fill=yellow!60!black, draw=none, domain=4:6.9] {gauss(10,2)}
            \closedcycle;
            \addplot [cyan!50!black] {gauss(2,0.5)};
            \addplot [cyan!50!black] {gauss(5,1)};
            \addplot [cyan!50!black] {gauss(10,2)};
            \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
            \node at (axis cs: 2,0.2) [font=\footnotesize, inner sep=1pt, above] {$\sigma 1$};
            \addplot[<->] coordinates {(3.5,0.12) (6.5,0.12)};
            \node at (axis cs: 5,0.12) [font=\footnotesize, inner sep=1pt, above] {$\sigma 2$};
            \addplot[<->] coordinates {(7,0.04) (13,0.04)};
            \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!

share|improve this question
    
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

1 Answer 1

up vote 3 down vote accepted

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.

output of below code

\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$}
    ]

  \addplot [tissue, domain=2.75:3.65] {gauss(2,0.5)}
  \closedcycle;
  \addplot [tissue, domain=4.9:6.5] {gauss(8,1)}
  \closedcycle;
  \addplot [plotline] {gauss(2,0.5)};
  \addplot [plotline] {gauss(8,1)};

  \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
  \node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
  \addplot[<->] coordinates {(6.5,0.12) (9.5,0.12)};
  \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$}
    ]

  \addplot [tissue, domain=2.75:3.65] {gauss(2,0.5)}
  \closedcycle;
  \addplot [tissue, domain=4.9:6.5] {gauss(8,1)}
  \closedcycle;
  \addplot [tissue, domain=9.5:11.1] {gauss(8,1)}
  \closedcycle;
  \addplot [tissue, domain=13:16] {gauss(19,2)}
  \closedcycle;
  \addplot [plotline] {gauss(2,0.5)};
  \addplot [plotline] {gauss(8,1)};
  \addplot [plotline] {gauss(19,2)};

  \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
  \node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
  \addplot[<->] coordinates {(6.5,0.12) (9.5,0.12)};
  \node at (axis cs: 8,0.12) [sigmalabel] {$\sigma 2$};
  \addplot[<->] coordinates {(16,0.04) (22,0.04)};
  \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$}
    ]

  \addplot [tissue, domain=2.75:3.65] {gauss(2,0.5)}
  \closedcycle;
  \addplot [tissue, domain=2:3.5] {gauss(5,1)}
  \closedcycle;
  \addplot [tissue, domain=6.5:8] {gauss(5,1)}
  \closedcycle;
  \addplot [tissue, domain=13:16] {gauss(19,2)}
  \closedcycle;
  \addplot [plotline] {gauss(2,0.5)};
  \addplot [plotline] {gauss(5,1)};
  \addplot [plotline] {gauss(19,2)};

  \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
  \node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
  \addplot[<->] coordinates {(3.5,0.12) (6.5,0.12)};
  \node at (axis cs: 5,0.12) [sigmalabel] {$\sigma 2$};
  \addplot[<->] coordinates {(16,0.04) (22,0.04)};
  \node at (axis cs: 19,0.04) [sigmalabel] {$\sigma 3$};


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

  \addplot [ubiq, domain=1.5:3.5] {gauss(5,1)}
  \closedcycle;
  \addplot [ubiq, domain=6.5:8.5] {gauss(5,1)}
  \closedcycle;
  \addplot [plotline] {gauss(5,1)};

  \addplot[<->] coordinates {(3.5,0.1) (6.5,0.1)};
  \node at (axis cs: 5,0.1) [sigmalabel] {$\sigma 1$};


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

  \addplot [ubiq, domain=3.75:4.65] {gauss(3,0.5)}
  \closedcycle;
  \addplot [ubiq, domain=2.5:4.5] {gauss(6,1)}
  \closedcycle;
  \addplot [plotline] {gauss(3,0.5)};
  \addplot [plotline] {gauss(6,1)};

  \addplot[<->] coordinates {(2.25,0.2) (3.75,0.2)};
  \node at (axis cs: 3,0.2) [sigmalabel] {$\sigma 1$};
  \addplot[<->] coordinates {(4.5,0.12) (7.5,0.12)};
  \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$}
     ]

  \addplot [ubiq, domain=2.75:3.65] {gauss(2,0.5)}
  \closedcycle;
  \addplot [ubiq, domain=2:3.5] {gauss(5,1)}
  \closedcycle;
  \addplot [ubiq, domain=6.5:8] {gauss(5,1)}
  \closedcycle;
  \addplot [ubiq, domain=4:6.9] {gauss(10,2)}
  \closedcycle;
  \addplot [plotline] {gauss(2,0.5)};
  \addplot [plotline] {gauss(5,1)};
  \addplot [plotline] {gauss(10,2)};

  \addplot[<->] coordinates {(1.25,0.2) (2.75,0.2)};
  \node at (axis cs: 2,0.2) [sigmalabel] {$\sigma 1$};
  \addplot[<->] coordinates {(3.5,0.12) (6.5,0.12)};
  \node at (axis cs: 5,0.12) [sigmalabel] {$\sigma 2$};
  \addplot[<->] coordinates {(7,0.04) (13,0.04)};
  \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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.