在组图中将一个图叠加到另一个图上

在组图中将一个图叠加到另一个图上

我正在尝试呈现一个组图,其中我基本上想展示进入第三个图的两步过渡。因此,在第一个图中,我只有一个正态分布。在第二个图中,我希望在背景中使用浅色,并在前景中使用直方图,从而实现相同的正态分布。在第三个图中,我希望在新图中保留背景中的正态分布。当前版本仅完成了 50%。如果您能帮助我修复它,我将不胜感激。以下是代码:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{amssymb, amsmath}
\usepackage{tikz}
\usepackage{xcolor}
\pgfplotsset{compat=1.7}

\usepackage{tikz}
\usepackage{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{every axis legend/.append style={%
cells={anchor=west}}
}
\usepgfplotslibrary{polar}
\usetikzlibrary{arrows}
\tikzset{>=stealth'}
\usetikzlibrary{matrix}
\usepgfplotslibrary{groupplots}

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

\begin{tikzpicture}
\begin{groupplot}[scale=0.63, group style={
                    group name=relcost, columns=3,
                    horizontal sep=1.1cm,
                    xlabels at=edge bottom,
                    ylabels at=edge left},
                    height=5cm, width=12cm,
                    xmin=-3,xmax=3,
                    %ymin=0,ymax=4,
                    %ytick={0},
                    axis lines=left,
                    xtick={-3,-2,-1,0,1,2,3},
                    ytick=\empty,
                    %xticklabels={0,2,4,6,8,10},
                    %yticklabel = $\pgfmathprintnumber{\tick}$,
                    %xticklabel = $\tick$
                    y post scale=0.63,
                    ylabel={frequency},legend columns = -1,
                    legend style={font=\small}]

   \nextgroupplot[samples=100,xlabel = {Standard deviations}]   
        \addplot [fill=cyan!20, draw=none, domain=-3:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=-3:-2] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=2:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=-2:-1] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=1:2] {gauss(0,1)} \closedcycle;
   \nextgroupplot[samples=100,xlabel = {Standard deviations}]
        \addplot [fill=cyan!20, draw=none, domain=-3:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=-3:-2] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=2:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=-2:-1] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=1:2] {gauss(0,1)} \closedcycle;

        \addplot [ybar=0pt, bar width=1, fill=orange!20, draw=orange!25] coordinates {(-2.5,8) (2.5, 22)};
        \addplot [ybar=0pt, bar width=1, fill=blue!20, draw=blue!25] coordinates {(-1.5,125) (1.5, 140)};
        \addplot [ybar=0pt, bar width=1, fill=cyan!20, draw=cyan!25] coordinates {(-0.5,362) (0.5, 343)};
   \nextgroupplot[xlabel = {Standard deviations}]   
        \addplot [ybar=0pt, bar width=1, fill=orange!10, draw=orange!25] coordinates {(-2.5,8.8) (2.5, 24.2)};
        \addplot [ybar=0pt, bar width=1, fill=orange!30, draw=orange!25] coordinates {(-2.5,7.2) (2.5, 19.8)};
        \addplot [ybar=0pt, bar width=1, fill=blue!10, draw=blue!25] coordinates {(-1.5,137.5) (1.5, 154)};
        \addplot [ybar=0pt, bar width=1, fill=blue!30, draw=blue!25] coordinates {(-1.5,112.5) (1.5, 126)};

        \addplot [ybar=0pt, bar width=1, fill=cyan!10, draw=cyan!25] coordinates {(-0.5,398.2) (0.5, 377.3)};
        \addplot [ybar=0pt, bar width=1, fill=cyan!30, draw=cyan!25] coordinates {(-0.5,325.8) (0.5, 308.7)};
  \end{groupplot}
  \end{tikzpicture}
\end{document}

答案1

vertical sep一种非常临时的可能性是通过将设置为适当的负值来创建两行。我不明白你想在第三列做什么。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{groupplots}

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

\begin{tikzpicture}
\begin{groupplot}[scale=0.63, group style={
                    group name=relcost, columns=3,rows=2,
                    horizontal sep=1.1cm,
                    vertical sep=-2.15cm,
                    xlabels at=edge bottom,
                    ylabels at=edge left},
                    height=5cm, width=12cm,
                    xmin=-3,xmax=3,
                    %ymin=0,ymax=4,
                    %ytick={0},
                    axis lines=left,
                    xtick={-3,-2,-1,0,1,2,3},
                    ytick=\empty,
                    %xticklabels={0,2,4,6,8,10},
                    %yticklabel = $\pgfmathprintnumber{\tick}$,
                    %xticklabel = $\tick$
                    y post scale=0.63,
                    ylabel={frequency},legend columns = -1,
                    legend style={font=\small}]

   \nextgroupplot[samples=100,xlabel = {Standard deviations}]   
        \addplot [fill=cyan!20, draw=none, domain=-3:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=-3:-2] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=2:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=-2:-1] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=1:2] {gauss(0,1)} \closedcycle;
   \nextgroupplot[samples=100,xlabel = {Standard deviations}]
        \addplot [fill=cyan!20, draw=none, domain=-3:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=-3:-2] {gauss(0,1)} \closedcycle;
        \addplot [fill=orange!20, draw=none, domain=2:3] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=-2:-1] {gauss(0,1)} \closedcycle;
        \addplot [fill=blue!20, draw=none, domain=1:2] {gauss(0,1)} \closedcycle;
   \nextgroupplot[xlabel = {Standard deviations}]   
        \addplot [ybar=0pt, bar width=1, fill=orange!10, draw=orange!25] coordinates {(-2.5,8.8) (2.5, 24.2)};
        \addplot [ybar=0pt, bar width=1, fill=orange!30, draw=orange!25] coordinates {(-2.5,7.2) (2.5, 19.8)};
        \addplot [ybar=0pt, bar width=1, fill=blue!10, draw=blue!25] coordinates {(-1.5,137.5) (1.5, 154)};
        \addplot [ybar=0pt, bar width=1, fill=blue!30, draw=blue!25] coordinates {(-1.5,112.5) (1.5, 126)};

        \addplot [ybar=0pt, bar width=1, fill=cyan!10, draw=cyan!25] coordinates {(-0.5,398.2) (0.5, 377.3)};
        \addplot [ybar=0pt, bar width=1, fill=cyan!30, draw=cyan!25] coordinates {(-0.5,325.8) (0.5, 308.7)};
   \nextgroupplot[group/empty plot]
   \nextgroupplot[]
        \addplot [opacity=0.5,ybar=0pt, bar width=1, fill=orange!20, draw=orange!25] coordinates {(-2.5,8) (2.5, 22)};
        \addplot [opacity=0.5,ybar=0pt, bar width=1, fill=blue!20, draw=blue!25] coordinates {(-1.5,125) (1.5, 140)};
        \addplot [opacity=0.5,ybar=0pt, bar width=1, fill=cyan!20, draw=cyan!25] coordinates {(-0.5,362) (0.5, 343)};
   \nextgroupplot[group/empty plot]
  \end{groupplot}
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容