使用 pgfplot 绘制人口回归函数

使用 pgfplot 绘制人口回归函数

我想要用 制作以下人口回归函数pgfplot

在此处输入图片描述

我尝试的代码是

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


\begin{document}

\begin{tikzpicture}[ % Define Normal Probability Function
declare function={
            normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));
        }
       ]
\begin{axis}[
    no markers
  , domain=-3.2:3.2
  , 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=12cm
  , xtick=\empty
  , ytick=\empty
  , enlargelimits=false
  , clip=false
  , axis on top
  , grid = major
  , hide x axis
  , hide y axis
  ]



\addplot[cyan!50!black, rotate=-45] (x, {normal(0, 1)});

\end{axis}


\end{tikzpicture}

\end{document}

在此处输入图片描述

任何帮助获取此图表的帮助都将不胜感激。谢谢

答案1

要绘制具有交换轴的函数,您可以使用\addplot (function, x);而不是正常的\addplot {function};

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}

\begin{tikzpicture}[ % Define Normal Probability Function
declare function={
            normal(\x,\m,\s) = 1/(2*\s*sqrt(pi))*exp(-(\x-\m)^2/(2*\s^2));
        }
       ]
\begin{axis}[
    no markers,
    domain=-3.2:3.2,
    samples=100,
    axis lines=left,
    enlarge x limits=true,
    xtick={0,0.5,1},
    xmajorgrids,
    xticklabels={},
    ytick=\empty,
    xticklabels={$x_1$, $x_2$, $x_3$},
    xlabel=$x$, xlabel style={at=(xticklabel cs:1), anchor=south},
    ylabel=$y$, ylabel style={at=(yticklabel cs:1), rotate=-90, anchor=east},
  ]


\addplot [samples=2, domain=0:1.4] {1.5*x};
\addplot[cyan!50!black, thick] ({normal(x, 0, 1)},x);
\addplot[cyan!50!black, thick, domain=-2.5:4.49] ({normal(x, 1.2, 1.5)+0.5},x);
\addplot[cyan!50!black, thick, domain=-1:4.4] ({normal(x, 2, 0.75)+1},x);

\end{axis}


\end{tikzpicture}

\end{document}

相关内容