群图

群图

我无法将 tikzpictures 放置在正确的位置...我想将 3 个绿色填充的图放在上方一行(alpha/2 位于正下方),将 3 个黄色填充的图放在下方一行(alpha/2 位于正下方)...我如何在这里指定新行?我尝试使用 \nodes,但由于某种原因它不起作用。

这里我遗漏了一些东西,因为我将小页面的宽度指定为 \linewidth,而文档的纸张宽度略大于行中 3 个图的宽度。

以下 MWE 生成该图: 在此处输入图片描述

不过,我希望它能生成类似于这张的图片(这是我手动制作的): 在此处输入图片描述

我目前拥有的代码如下:

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

一旦解决了这个问题,我想用适当的密度设置转换生成的 pdf,但我不知道该怎么做...但这是次要的,因为我总是可以打印屏幕或某些东西...谢谢!

答案1

这个答案分为两部分。第一部分是关于如何使用groupplotstp 在 3x2 网格中组织图,第二部分是关于转换为 PNG 的方法。

群图

您可以使用groupplots库来排列图。请参阅5.5 分组图在手册中。

groupplots非常适合您想要在网格中组织多个图的情况,例如这里。您使用groupplot环境而不是axis,并使用开始新轴\nextgroupplot。在环境选项中,groupplot您可以指定所有子轴应相同的设置,例如宽度/高度、轴线样式等。

group style={group size=3 by 2}网格的列数设置为 3,行数设置为 2。还可以用和group style定义图之间的距离。horizontal sepvertical sep

我稍微整理了一下代码。还可以进行其他自定义,例如可以定义一个\newcommand来绘制箭头,顶部有 sigma,但我还没有这样做。我所做的是:

  • 定义了四种新风格:

    • sigmalabel- 对于具有 `$\sigma 1$ 的节点
    • tissue- 对于\closedcycle前三个子图中的图,定义颜色和draw=none
    • ubiq- 类似于tissue,最后三个
    • plotline- 仅绘制线条的颜色
  • 将所有常见设置移至groupplot环境中,而不是为每个设置重复此操作\nextgroupplot
  • \footnotesize我没有添加每一个,而是xtick更改了x tick label style
  • 我没有将文本放在 之外tikzpicture,而是将它们添加为相对于轴放置的节点。通过添加group name=some stringgroup style,每个子轴将成为一个命名节点,some string c1r2网格第一列第二行中的轴也是如此。此外,some string c1r2.north west将是它的右上角。文本是相对于此类坐标放置的。

下面的代码输出

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

转换为 PNG

该类standalone允许您将tikzpictures 直接转换为 PNG。这需要安装 ImageMagick,有关详细信息,请参阅手册。首先从tikzpicture环境中删除环境之外的所有内容document,然后将 eg 添加tikz,convert={density=150}到类的选项中。编译时,您必须启用shell-escape。代码看起来像

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

每个tikzpicture将在 PDF 中被赋予一个单独的页面,并创建一个单独的 PNG。

相关内容