使用 tikz 生成下图(包含正态分布及其旋转版本)

使用 tikz 生成下图(包含正态分布及其旋转版本)

我正在尝试用 制作下图tikz在此处输入图片描述

这是我目前得到的 在此处输入图片描述

具有以下 MWE:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}

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

\begin{tikzpicture}
\begin{axis}[
    no markers
  , domain=-7.5:25.5
  , samples=100
  , ymin=0
  , axis lines*=left
  , xlabel=
   , 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=20cm
  , xtick=\empty
  , ytick=\empty
  , enlargelimits=false
  , clip=false
  , axis on top
  , grid = major
  , hide y axis
  , hide x axis
  ]



\draw[thick, ->] (axis cs: 0, 0) -- (axis cs: 8, 0) node[anchor = north west] {};
\draw[thick, ->] (axis cs: 0, 0) -- (axis cs: 0, 2) node[anchor = south east] {y};

% Normal Distribution 1
\addplot[blue, ultra thick,restrict x to domain=1:5] {gauss(x, 3, 1)};
\pgfmathsetmacro\valueA{gauss(0, 3, 1)}
\draw [dashed, thick, blue] (axis cs:0, 0) -- (axis cs:0, \valueA);
\node[below] at (axis cs:0, -0.02)  {\Large \textcolor{blue}{$Z$}};
\draw[thick, blue] (axis cs:-0.0, -0.01) -- (axis cs:0.0, 0.01);

% Normal Distribution 2
\addplot[rotate=90, green, ultra thick,restrict x to domain=-2:6] {gauss(x, 2, 1)};

% Normal Distribution 3
\addplot[rotate=90, red, ultra thick,restrict x to domain=0:8] {gauss(x, 4, 1)};

\end{axis}


\end{tikzpicture}

\end{document}

任何能帮助获取所需图表的帮助都将不胜感激。提前致谢。

答案1

代码可能有点乱。我使用了两个axis环境,第二个环境是旋转的。第一个环境的高度等于第二个环境的宽度。沿图添加坐标,并使用这些坐标在第二个轴后绘制虚线。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\begin{document}

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

\begin{tikzpicture}
\begin{axis}[
    name=axis1,
    no markers
  , domain=0:10,ylabel=$y$,
  , samples=200
  , ymin=0,ymax=2,xmin=0,xmax=6,
  , axis lines*=left
  , xlabel=
   , 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=10cm
  , width=8cm,scale only axis,
  , xtick=3,xticklabels={$z$},
  , ytick=\empty
  , enlargelimits=false
  , axis on top
  ]

% Normal Distribution 1
\addplot[blue, ultra thick,restrict x to domain=0.5:5.5] {gauss(x, 3, 1)}
  coordinate [pos=0.02] (b1)
  coordinate [pos=0.98] (b2)
  coordinate [pos=0.7] (bm);

\pgfmathsetmacro\valueA{gauss(0, 3, 1)}

\end{axis}
% Normal Distribution 2
\begin{axis}[
  clip=false,
  samples=100,
  ymin=0,
  xmin=-6,xmax=9,
  scale only axis,
  domain=-2:10,
  rotate=90,
  at={(axis1.south west)},
  hide axis,
  anchor=south east,
  width=10cm,
  height=4cm]

\addplot[green, ultra thick,restrict x to domain=-2:6] {gauss(x, 2, 1)}
  coordinate [pos=0] (g1)
  coordinate [pos=1] (g2)
  coordinate [pos=0.5] (gm);

% Normal Distribution 3
\addplot[red, ultra thick,restrict x to domain=0:8] {gauss(x, 4, 1)}
  coordinate [pos=0] (r1)
  coordinate [pos=1] (r2)
  coordinate [pos=0.5] (rm);
\end{axis}

\draw [very thick] (g1-|b1) -- (g2-|b2);
\draw [very thick] (r1-|b1) -- (r2-|b2);

\draw [dashed] (r1) -| (g1-|b1);
\draw [dashed] (g1) -| (b1);

\draw [dashed] (r2) -| (g2-|b2) node[pos=0.5,right] {$x=+$};
\draw [dashed] (g2) -| (b2) node[pos=0.5,right] {$x=-$};


\draw [shorten <=1mm,Stealth-,thick] (bm) -- ++(3mm,4mm)
  node[above,align=center] 
  {Natural\\variability\\ in $z$};

\path (rm) ++(3mm,2cm) node[align=right] (var) {Variability in $y$\\transmitted\\from$z$};
\draw [-Stealth] (var.west) ++(1.5em,-1ex) -- (gm);
\draw [-Stealth] (var.west) ++(1.5em,-1ex) -- (rm);
\end{tikzpicture}

\end{document}

相关内容