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:
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:
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}
set layer
, as Stefan Pinnow recently explained me. So you could just addset 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.set layer
is something new to me :Dpre 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.xshift
andyshift
which are given to theaxis
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?