如何使用 pgfplots 繪製一組單位向量,其角度是從常態分佈中選擇的?

如何使用 pgfplots 繪製一組單位向量,其角度是從常態分佈中選擇的?

我想表示N單位向量,其角度是從常態分佈中選擇的,mean=90, sd=10例如 ( ),如下圖所示。

我想知道如何使用 繪製相同的內容pgfplots

在此輸入影像描述

答案1

歡迎!像這樣的東西嗎?

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={gauss(\x)=exp(-pow(\x/10,2));},>=stealth]
 \begin{axis}[hide axis,xmin=-1,xmax=1,ymin=0,ymax=1]
  \pgfmathsetmacro{\myangle}{0}
  \draw[->] (0,0) -- (90:1);
  \pgfplotsinvokeforeach{0,...,10}{
   \pgfmathsetmacro{\myangle}{\myangle+1/(gauss(\myangle))}
   \edef\temp{\noexpand\draw[->] (0,0) -- (90+\myangle:1);
   \noexpand\draw[->] (0,0) -- (90-\myangle:1);}
   \temp 
  }
 \end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

或用極軸。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{polar}
\begin{document}
\begin{tikzpicture}[declare function={gauss(\x)=exp(-pow(\x/10,2));},>=stealth]
 \begin{polaraxis}[ymax=1,xmin=0,xmax=180,ytick=\empty]
  \pgfmathsetmacro{\myangle}{0}
  \draw[->] (0,0) -- (90,1);
  \pgfplotsinvokeforeach{0,...,10}{
   \pgfmathsetmacro{\myangle}{\myangle+1/(gauss(\myangle))}
   \edef\temp{\noexpand\draw[->] (0,0) -- (90+\myangle,1);
   \noexpand\draw[->] (0,0) -- (90-\myangle,1);}
   \temp 
  }
 \end{polaraxis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容