3

I am trying to plot a function as shown below:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \pgfmathdeclarefunction{gauss}{2}{% normal distribution where #1 = mu and #2 = sigma
        \pgfmathparse{exp(-((x-#1)^2)/(2*#2^2))}%
    }
    \begin{tikzpicture}[every axis/.style={width=4cm}]
    \begin{axis}[
    name=axis6, %axis 6
    xshift = 1.15in,
    yshift = -2.5in,
    no markers, domain=-0.7:0.7, samples=100,
    %axis lines*=left,
    %xlabel=$x$, 
    ylabel=$y$,
    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=12cm,
    xtick={-0.7,0,0.7},
    %xticklabels={-15, 0,  15},
    %ytick={0 1},
    ymin=0,
    ymax=1.2,
    enlargelimits=false, clip=false, axis on top,
    %grid = major
    ]
    \addplot [fill=gray!80, draw=none, domain=-0.7:-0.125] {gauss(0,.2)} \closedcycle;
    \addplot [fill=gray!80, draw=none, domain=0.125:0.7] {gauss(0,.2)} \closedcycle;
    \path[name path=axi] (axis cs:-0.15,0.75) -- (axis cs:0.15,0.75);
    \path[name path=axj] (axis cs:-0.15,0) -- (axis cs:0.15,0);
    %from this part things go bananas :/
%   \addplot [
%   thick,
%   color=gray,
%   fill=gray!80, 
%   %fill opacity=0.05
%   ]
%   fill between[
%   of=axi and axj,
%   %soft clip={domain=0:1},
%   ];
    %
%   \path[name path=axk] (axis cs:-0.7,0.2) -- (axis cs:-0.35,0.2);
%   \path[name path=axl] (axis cs:-0.7,0) -- (axis cs:-0.35,0);
%   \addplot [
%   thick,
%   color=gray,
%   fill=gray!20, 
%   %fill opacity=0.05
%   ]
%   fill between[
%   of=axk and axl,
%   %soft clip={domain=0:1},
%   ];  
    \addplot [gray, dash dot] {gauss(-0.7,.2)};
    \addplot [black, dashed] {gauss(-0.35,.2)};
    \addplot [gray] {gauss(0,.2)};
    \addplot [black!80] {gauss(0.35,.2)};
    \addplot [black, dotted] {gauss(0.7,.2)};
    \node (bar6a) at (0,1.4){};
    \end{axis}
    \end{tikzpicture}
\end{document}

This works good, giving me:

enter image description here

But as soon as I include the fill-between part of axis6 in the figure, I dont get the axis6 at all. I am not able to find what is going wrong here:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \pgfmathdeclarefunction{gauss}{2}{% normal distribution where #1 = mu and #2 = sigma
        \pgfmathparse{exp(-((x-#1)^2)/(2*#2^2))}%
    }
    \begin{tikzpicture}[every axis/.style={width=4cm}]
    \begin{axis}[
    name=axis6, %axis 6
    xshift = 1.15in,
    yshift = -2.5in,
    no markers, domain=-0.7:0.7, samples=100,
    %axis lines*=left,
    %xlabel=$x$, 
    ylabel=$y$,
    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=12cm,
    xtick={-0.7,0,0.7},
    %xticklabels={-15, 0,  15},
    %ytick={0 1},
    ymin=0,
    ymax=1.2,
    enlargelimits=false, clip=false, axis on top,
    %grid = major
    ]
    \addplot [fill=gray!80, draw=none, domain=-0.7:-0.125] {gauss(0,.2)} \closedcycle;
    \addplot [fill=gray!80, draw=none, domain=0.125:0.7] {gauss(0,.2)} \closedcycle;
    \path[name path=axi] (axis cs:-0.15,0.75) -- (axis cs:0.15,0.75);
    \path[name path=axj] (axis cs:-0.15,0) -- (axis cs:0.15,0);
    %from this part things go bananas :/
    \addplot [
    thick,
    color=gray,
    fill=gray!80, 
    %fill opacity=0.05
    ]
    fill between[
    of=axi and axj,
    %soft clip={domain=0:1},
    ];
    %
%   \path[name path=axk] (axis cs:-0.7,0.2) -- (axis cs:-0.35,0.2);
%   \path[name path=axl] (axis cs:-0.7,0) -- (axis cs:-0.35,0);
%   \addplot [
%   thick,
%   color=gray,
%   fill=gray!20, 
%   %fill opacity=0.05
%   ]
%   fill between[
%   of=axk and axl,
%   %soft clip={domain=0:1},
%   ];  
    \addplot [gray, dash dot] {gauss(-0.7,.2)};
    \addplot [black, dashed] {gauss(-0.35,.2)};
    \addplot [gray] {gauss(0,.2)};
    \addplot [black!80] {gauss(0.35,.2)};
    \addplot [black, dotted] {gauss(0.7,.2)};
    \node (bar6a) at (0,1.4){};
    \end{axis}
    \end{tikzpicture}
\end{document}

giving me nothing. Any help will be appreciated :)

On the other hand: It works-well,

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \pgfmathdeclarefunction{gauss}{2}{% normal distribution where #1 = mu and #2 = sigma
        \pgfmathparse{exp(-((x-#1)^2)/(2*#2^2))}%
    }
    \begin{tikzpicture}[every axis/.style={width=4cm}]
\begin{axis}[ %axis 2
name=axis2,
no markers, domain=-10:10, samples=100,
%axis lines*=left,
%xlabel=$x$, 
ylabel=$y$,
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=12cm,
xtick={-10,0,10},
%xticklabels={-15, 0,  15},
ytick=\empty,
ymin=0,
ymax=1.2,
enlargelimits=false, clip=false, axis on top,
%grid = major
]
\addplot [fill=gray!20, draw=none, domain=-10:-2.5] {gauss(0,3)} \closedcycle;
\addplot [fill=gray!20, draw=none, domain=2.5:10] {gauss(0,3)} \closedcycle;
\path[name path=axa] (axis cs:-2.5,0.7) -- (axis cs:2.5,0.7);
\path[name path=axb] (axis cs:-2.5,0) -- (axis cs:2.5,0);
\addplot [
thick,
color=gray,
fill=gray!20, 
%fill opacity=0.05
]
fill between[
of=axa and axb,
%soft clip={domain=0:1},
];
%
\path[name path=axc] (axis cs:5,0.2) -- (axis cs:10,0.2);
\path[name path=axd] (axis cs:5,0) -- (axis cs:10,0);
\addplot [
thick,
color=black,
fill=black!40, 
%fill opacity=0.05
]
fill between[
of=axc and axd,
%soft clip={domain=0:1},
];
\addplot [gray, dash dot] {gauss(-10,3)};
\addplot [black, dashed] {gauss(-5,3)};
\addplot [gray] {gauss(0,3)};
\addplot [black!80] {gauss(5,3)};
\addplot [black, dotted] {gauss(10,3)};
\node (bar2a) at (10,1) {};
\node (bar2b) at (10,0.2) {};
\end{axis}
    \end{tikzpicture}
\end{document}

giving me:

enter image description here

The full script:

%&lualatex
% !TeX TXS-program:compile = txs:///lualatex/[--shell-escape]
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \pgfmathdeclarefunction{gauss}{2}{% normal distribution where #1 = mu and #2 = sigma
        \pgfmathparse{exp(-((x-#1)^2)/(2*#2^2))}%
    }
    \begin{tikzpicture}[every axis/.style={width=4cm}]
    \begin{axis}[
    name=axis1 %axis 1
    no markers, domain=-10:10, samples=100,
    %axis lines*=left,
    %xlabel=$x$, 
    ylabel=$y$,
    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=12cm,
    xtick={-10,0,10},
    %xticklabels={-15, 0,  15},
    %ytick={0 1},
    ymin=0,
    ymax=1.2,
    enlargelimits=false, clip=false, axis on top,
    %grid = major
    ]
    \addplot [gray, dash dot] {gauss(-10,3)};
    \addplot [black, dashed] {gauss(-5,3)};
    \addplot [gray] {gauss(0,3)};
    \addplot [black!80] {gauss(5,3)};
    \addplot [black, dotted] {gauss(10,3)};
    \addplot [color=black] coordinates { (2,0) (2,1.2) };
    \node (bar1a) at (1,1){};
    \node (bar1b) at (1,0.2){};
    \end{axis}
    \begin{axis}[ %axis 2
    xshift = 1.15in,
    name=axis2,
    no markers, domain=-10:10, samples=100,
    %axis lines*=left,
    %xlabel=$x$, 
    ylabel=$y$,
    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=12cm,
    xtick={-10,0,10},
    %xticklabels={-15, 0,  15},
    ytick=\empty,
    ymin=0,
    ymax=1.2,
    enlargelimits=false, clip=false, axis on top,
    %grid = major
    ]
    \addplot [fill=gray!20, draw=none, domain=-10:-2.5] {gauss(0,3)} \closedcycle;
    \addplot [fill=gray!20, draw=none, domain=2.5:10] {gauss(0,3)} \closedcycle;
    \path[name path=axa] (axis cs:-2.5,0.7) -- (axis cs:2.5,0.7);
    \path[name path=axb] (axis cs:-2.5,0) -- (axis cs:2.5,0);
    \addplot [
    thick,
    color=gray,
    fill=gray!20, 
    %fill opacity=0.05
    ]
    fill between[
    of=axa and axb,
    %soft clip={domain=0:1},
    ];
    %
    \path[name path=axc] (axis cs:5,0.2) -- (axis cs:10,0.2);
    \path[name path=axd] (axis cs:5,0) -- (axis cs:10,0);
    \addplot [
    thick,
    color=black,
    fill=black!40, 
    %fill opacity=0.05
    ]
    fill between[
    of=axc and axd,
    %soft clip={domain=0:1},
    ];
    \addplot [gray, dash dot] {gauss(-10,3)};
    \addplot [black, dashed] {gauss(-5,3)};
    \addplot [gray] {gauss(0,3)};
    \addplot [black!80] {gauss(5,3)};
    \addplot [black, dotted] {gauss(10,3)};
    \node (bar2a) at (10,1) {};
    \node (bar2b) at (10,0.2) {};
    \end{axis}
    \begin{axis}[ %axis 3
    yshift = -1in,
    name=axis3,
    no markers, domain=-15:15, samples=100,
    %axis lines*=left,
    xlabel=$x$, ylabel=$y$,
    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=12cm,
    xtick={-15, 0,  15}, 
    %ytick={0 1},
    enlargelimits=false, clip=false, axis on top,
    %grid = major,
    ymin=0,
    ymax=1.2,
    ]
    \addplot [gray, dash dot] {gauss(-15,3)};
    \addplot [black, dashed] {gauss(-7.5,3)};
    \addplot [gray] {gauss(0,3)};
    \addplot [black!80] {gauss(7.5,3)};
    \addplot [black, dotted] {gauss(15,3)};
    %\addplot [cyan!50!black] {gauss(6.5,1)};
    %\draw [yshift=-0.6cm, latex-latex](axis cs:4,0) -- node [fill=white] {$1.96\sigma$} (axis cs:5.96,0);
    \addplot [color=black] coordinates { (-4,0) (-4,1.2) };
    \node (bar3a) at (-4,1) {};
    \node (bar3b) at (-4,0.2) {};
    \end{axis}
    \begin{axis}[ %axis 4
    xshift = 1.15in,
    yshift = -1in,
    name=axis4,
    no markers, domain=-15:15, samples=100,
    %axis lines*=left,
    %xlabel=$x$, 
    ylabel=$y$,
    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=12cm,
    xtick={-15, 0,  15},
    ytick=\empty,
    ymin=0,
    ymax=1.2,
    enlargelimits=false, clip=false, axis on top,
    %grid = major
    ]
    \addplot [fill=black!30, draw=none, domain=-15:-10] {gauss(-7.5,3)} \closedcycle;
    \addplot [fill=black!30, draw=none, domain=-5:15] {gauss(-7.5,3)} \closedcycle;
    \addplot [fill=gray!20, draw=none, domain=5.3:15] {gauss(0,3)} \closedcycle;
    \path[name path=axe] (axis cs:-10,0.7) -- (axis cs:-5,0.7);
    \path[name path=axf] (axis cs:-10,0) -- (axis cs:-5,0);
    \addplot [
    thick,
    color=black,
    fill=black!30, 
    %fill opacity=0.05
    ]
    fill between[
    of=axe and axf,
    %soft clip={domain=0:1},
    ];
    %
    \path[name path=axg] (axis cs:-5,0.2) -- (axis cs:5.3,0.2);
    \path[name path=axh] (axis cs:-5,0) -- (axis cs:5.3,0);
    \addplot [
    thick,
    color=gray,
    fill=gray!20, 
    %fill opacity=0.05
    ]
    fill between[
    of=axg and axh,
    %soft clip={domain=0:1},
    ];
    \addplot [gray, dash dot] {gauss(-15,3)};
    \addplot [black, dashed] {gauss(-7.5,3)};
    \addplot [gray] {gauss(0,3)};
    \addplot [black!80] {gauss(7.5,3)};
    \addplot [black, dotted] {gauss(15,3)};
    \node (bar4a) at (15,1) {};
    \node (bar4b) at (15,0.2) {};
    \node (bar4c) at (0,-0.2) {};
    \end{axis}
    \begin{axis}[
    name=axis6, %axis 6
    xshift = 1.15in,
    yshift = -2.5in,
    no markers, domain=-0.7:0.7, samples=100,
    %axis lines*=left,
    %xlabel=$x$, 
    ylabel=$y$,
    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=12cm,
    xtick={-0.7,0,0.7},
    %xticklabels={-15, 0,  15},
    %ytick={0 1},
    ymin=0,
    ymax=1.2,
    enlargelimits=false, clip=false, axis on top,
    %grid = major
    ]
    \addplot [fill=gray!80, draw=none, domain=-0.7:-0.125] {gauss(0,.2)} \closedcycle;
    \addplot [fill=gray!80, draw=none, domain=0.125:0.7] {gauss(0,.2)} \closedcycle;
    \path[name path=axi] (axis cs:-0.15,0.75) -- (axis cs:0.15,0.75);
    \path[name path=axj] (axis cs:-0.15,0) -- (axis cs:0.15,0);
    %from this part things go bananas :/ due to shifts :(
%   \addplot [
%   thick,
%   color=gray,
%   fill=gray!80, 
%   %fill opacity=0.05
%   ]
%   fill between[
%   of=axi and axj,
%   %soft clip={domain=0:1},
%   ];
    %
%   \path[name path=axk] (axis cs:-0.7,0.2) -- (axis cs:-0.35,0.2);
%   \path[name path=axl] (axis cs:-0.7,0) -- (axis cs:-0.35,0);
%   \addplot [
%   thick,
%   color=gray,
%   fill=gray!20, 
%   %fill opacity=0.05
%   ]
%   fill between[
%   of=axk and axl,
%   %soft clip={domain=0:1},
%   ];  
    \addplot [gray, dash dot] {gauss(-0.7,.2)};
    \addplot [black, dashed] {gauss(-0.35,.2)};
    \addplot [gray] {gauss(0,.2)};
    \addplot [black!80] {gauss(0.35,.2)};
    \addplot [black, dotted] {gauss(0.7,.2)};
    \node (bar6a) at (0,1.4){};
    \end{axis}
    \draw [color=black,dash dot] (bar1a) -- (bar2a);
    \draw [color=black,dash dot] (bar1b) -- (bar2b);
    \draw [color=black,dash dot] (bar3a) -- (bar4a);
    \draw [color=black,dash dot] (bar3b) -- (bar4b);
    \path [->, draw, color=black] (bar4c) -- node [midway,left] {something}(bar6a);
%   \draw [color=black,dash dot] (bar2) -- (bar3);
%   \draw [color=black,dash dot] (bar3) -- (bar4);
%   \draw [->,thick,color=red,dashed] (bar3) -- (bar4);
    %       \begin{scope}[every node/.style={text width=7cm,align=left}]
    %       \node [below] at (axis1.south) {\captionof{figure}{First caption}};
    %       \node [below] at (axis2.south) {\captionof{figure}{Second caption}};
    %       \node [below] at (axis3.south) {\captionof{figure}{Third caption}};
    %       \end{scope}
    \end{tikzpicture}
\end{document}
14
  • 1
    I have no solution (at the moment) but it seems that the issue is related to the fact that attempts to fill areas between the plots issue a set layer, as Stefan Pinnow recently explained me. So you could just add set layers to have the effect. Presumably this clashes with something else you have in your plot, but I am not sure which element that is.
    – user121799
    Dec 13, 2018 at 10:20
  • @marmot Could you explain me in more detail? set layer is something new to me :D Dec 13, 2018 at 10:22
  • 1
    The layers are discussed in section 4.27.2 of the manual. Fills are made in the pre main layer by default, such that they do not cover plots or axes. This requires that the layers are set, which seems to clash for some reasons (that I don't understand) with your plot. axis on top also sets layers (but in a different order), strangely enough I cannot use them in your code.
    – user121799
    Dec 13, 2018 at 10:28
  • 1
    The mess is caused by xshift and yshift which are given to the axis options. Because I am not 100% sure what the final graph should look like, it is hard to propose a solution. What to you need the above given options for? Dec 13, 2018 at 11:00
  • 1
    Your question says that "fillbetween suddenly broke". Now you know that this is caused by shifts. So ask the question like "fillbetween breaks during a shift". This will make it easier to find this problem with a search engine.
    – AndréC
    Dec 16, 2018 at 18:24

1 Answer 1

3

As stated in the comment below the question the shifts (xshift/yshift) are causing the mess. Assuming you use them to place the several axis environments aligned next and on top of each other I suggest to use proper at and anchor statements. This gives the attached result.

It follows the refactored code which is much cleaner than the starting code making use of styles in many places. For details please have a look at the comments in the code.

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        % use this `compat' level or higher to make use of Lua when compiling
        % with lualatex. This `compat' level also makes `axis cs:' the default
        % coordinate system for TikZ coordinates
        compat=1.12,
        % declare some constants and the Gauss function for later use
        /pgf/declare function={
            ymin = 0;
            ymax = 1.2;
            %
            FillHeight = 0.7;
            %
            LowerLine = 0.2;
            UpperLine = 1.0;
            %
            xVertBarAxis1 = 2;
            xVertBarAxis3 = -4;
            %
            gauss(\mu,\sigma) = exp(-((x-\mu)^2)/(2*\sigma^2));
        },
        % define a custom style for the `axis' so we don't have to repeat all
        % the options over and over again. Of course this also makes it much
        % easier to change the style of these plots
        my axis style/.style={
            ylabel=$y$,
            ymin=ymin,
            ymax=ymax,
            samples=101,
            enlargelimits=false,
            axis on top,
            % use the custom created cycle list here
            cycle list name=my cycle list,
            every axis y label/.style={
                at=(current axis.above origin),
                anchor=south,
            },
            % simply add the `xaxis' path to every plot which uses this style
            % (so again it is not needed to repeat this)
            execute at begin axis={
                \path [name path=xaxis]
                    (\pgfkeysvalueof{/pgfplots/xmin},0) --
                    (\pgfkeysvalueof{/pgfplots/xmax},0)
                ;
            },
            % use `extra x ticks' to add the vertical lines to the plots ...
            % (the `#1' means that an optional argument to this style will
            %  be forwarded here)
            extra x ticks={#1},
            % ... and this is the style which should be applied to the extra ticks
            extra x tick style={
                xticklabels={},
                major tick length=0pt,
                grid=major,
                grid style={
                    draw=black,
                },
            },
        },
        % define some more custom styles for later use
        my light gray fill/.style={
            draw=none,
            fill=gray!20,
        },
        my dark gray fill/.style={
            draw=none,
            fill=black!40,
        },
    }
    % create a custom `cycle list' so that one don't has to repeat this
    % over and over again
    \pgfplotscreateplotcyclelist{my cycle list}{
        gray,dash dot\\
        black,dashed\\
        gray\\
        black!80\\
        black,dotted\\
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        % name this plot so the others can be placed relative to this one
        name=axis1,
        % use the (optional) argument of the custom style
        % to place the vertical line at the given position
        my axis style={2},
        xtick={-10,0,10},
        domain=-10:10,
    ]
        % with the custom `cycle list' this can be simplified to
        \foreach \i in {-10,-5,...,10} {
            \addplot {gauss(\i,3)};
        }

        % then here it only remains to place the dummy coordinates for the
        % horizontal lines, which will be drawn after all `axis' environments
        \begin{scope}[
            xshift=-2.5mm,
        ]
            \coordinate (bar1a) at (xVertBarAxis1,LowerLine);
            \coordinate (bar1b) at (xVertBarAxis1,UpperLine);
        \end{scope}
    \end{axis}

    \begin{axis}[
        name=axis2,
        % ---------------------------------------------------------------------
        my axis style,
        % place the other `axis' environments relative to the previous ones
        at={(axis1.right of east)},
        anchor=left of west,
        % ---------------------------------------------------------------------
        xtick={-10,0,10},
        ytick=\empty,
        domain=-10:10,
    ]
        \foreach \i in {-10,-5,...,10} {
            \addplot {gauss(\i,3)};
        }

        % this is one way of adding the fill
        % later it will be shown another one
        % ----------------------------------
        % put this fill on the same layer as the `fill between' stuff
        \pgfonlayer{pre main}
        % use the custom style here
        \addplot [my dark gray fill] coordinates {
            (0,LowerLine)
            (10,LowerLine)
        }
            \closedcycle
        ;
        \endpgfonlayer

        % here I create a dummy path which is than used by `fill between'
        % (optimally this is not needed, but `soft clip={domain y=0:FillHeight}'
        %  did some strange things)
        \addplot [
            draw=none,
            name path=gauss,
        ] {min(FillHeight, gauss(0,3))};
        \addplot [my light gray fill] fill between [
            of=gauss and xaxis,
        ];

        % this time we need to place coordinates for the horizontal lines
        % at the maximum x values, which are not set explicitly. But we can
        % get them with the help of `\pgfkeysvalueof{...}'.
        \coordinate (bar2a) at (\pgfkeysvalueof{/pgfplots/xmax},LowerLine);
        \coordinate (bar2b) at (\pgfkeysvalueof{/pgfplots/xmax},UpperLine);
    \end{axis}

    \begin{axis}[
        name=axis3,
        % ---------------------------------------------------------------------
        my axis style={-4},
        at={(axis1.below south)},
        anchor=above north,
        % ---------------------------------------------------------------------
        xlabel=$x$,
        xtick={-15,0,15},
        domain=-15:15,
    ]
        \foreach \i in {-15,-7.5,...,15} {
            \addplot {gauss(\i,3)};
        }

        \begin{scope}[
            xshift=-5mm,
        ]
            \coordinate (bar3a) at (xVertBarAxis3,LowerLine);
            \coordinate (bar3b) at (xVertBarAxis3,UpperLine);
        \end{scope}
    \end{axis}

    \begin{axis}[
        name=axis4,
        % ---------------------------------------------------------------------
        my axis style,
        at={(axis3.right of east)},
        anchor=left of west,
        % ---------------------------------------------------------------------
        xtick={-15,0,15},
        ytick=\empty,
        domain=-15:15,
    ]

        \foreach \i in {-15,-7.5,...,15} {
            \addplot {gauss(\i,3)};
        }

        \addplot [
            draw=none,
            name path=gauss1,
            samples=201,
        ] {min(LowerLine, gauss(0,3))};
        \addplot [my light gray fill] fill between [
            of=gauss1 and xaxis,
        ];

        \addplot [
            draw=none,
            name path=gauss2,
            samples=201,
        ] {min(FillHeight, gauss(-7.5,3))};

        \addplot [my dark gray fill] fill between [
            of=gauss2 and xaxis,
        ];

        \coordinate (bar4a) at (\pgfkeysvalueof{/pgfplots/xmax},LowerLine);
        \coordinate (bar4b) at (\pgfkeysvalueof{/pgfplots/xmax},UpperLine);
    \end{axis}

    \begin{axis}[
        name=axis6,
        % ---------------------------------------------------------------------
        my axis style,
        at={(axis4.below south)},
        % because there needs to be some more space for the arrow between
        % the plots, we increase the gab
        yshift=-10mm,
        anchor=above north,
        % ---------------------------------------------------------------------
        xtick={-0.7,0,0.7},
        domain=-0.7:0.7,
    ]

        \foreach \i in {-0.7,-0.35,...,0.7} {
            \addplot {gauss(\i,0.2)};
        }

        \pgfonlayer{pre main}
        \addplot [my light gray fill] coordinates {
            (-0.7,LowerLine)
            (0,LowerLine)
        }
            \closedcycle
        ;
        \endpgfonlayer

        \addplot [
            draw=none,
            name path=gauss,
            samples=201,
        ] {min(0.75, gauss(0,0.2))};

        \addplot [my dark gray fill] fill between [
            of=gauss and xaxis,
        ];
    \end{axis}

    % draw the horizontal lines between the upper and middle row of plots
    \draw [dash dot]
        (bar1a) -- (bar2a)
        (bar1b) -- (bar2b)
        (bar3a) -- (bar4a)
        (bar3b) -- (bar4b)
    ;

    % draw the arrow between the lower right two plots
    \draw [->]
        % if you want to, you can shift it a bit, as shown here using the
        % optional argument of the coordinate
        ([xshift=10mm] axis6.above north)
            -- node [left] {something}
        ([xshift=10mm] axis4.below south)
    ;

\end{tikzpicture}
\end{document}

image showing the result of above code

6
  • The code in principles works as I wanted. You can basically see these as a two-set membership functions from which I derive something. Simply, put applying some set-theory to the plots in (1,2) -- (2,2), I can derive something like (3,2). Using that arrow, I basically explain or simply mention what I am doing. More of a flow of concepts. Nevertheless, thanks for the solution (+1), it would be great, if I can have it with those arrows as well. Also, I am a novice when it comes to making diagrams with TeX ;) So, please feel free to correct whichever you deem necessary! Dec 13, 2018 at 13:26
  • 1
    @Raaja, so would you like to have an arrow from the top of the lower right plot to the bottom of the middle right plot with some text and thus that the lower right plot has a greater distance to the above plot than between the other plots? Dec 13, 2018 at 13:58
  • Voila! That's exactly what I want. Dec 13, 2018 at 13:59
  • 1
    @Raaja, please have a look at the refactored code. Hopefully this makes the concept clear, also if the result now is not exactly what you are looking for. But I think now you will be able to modify it to your needs. (There could be done more "automation"/styling, but we don't want to make things too complicated ;) Dec 13, 2018 at 19:23
  • 1
    All revisions are available by pressing on "edited ..." in the middle of the bottom of the answer (left to the name). A short link to the first revision is tex.stackexchange.com/revisions/464697/1, which hopefully is enough. Dec 14, 2018 at 7:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .