我的问题
我可以轻松绘制正态分布,这要归功于Jake 的这个回答.那鬼呢?
语境
在教授概率时,这张图片总能打破僵局:)
(并不是我太在意,但万圣节也快到了)
我推测使用 Inkscape 可以实现(但我不熟悉它)。
Paul Gaborit 的回答在我的 MWE 中使用hobby
我尝试适应的包(您会发现,它的效果很差,说实话,太过手动了)。
我很高兴看到不同的方法(纯 tikz、pgfplot、其他库……)。
\documentclass[tikz]{standalone}
\usetikzlibrary{hobby}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[use Hobby shortcut]
\draw[
help lines,
line width=0.1pt,
blue,
] (-20, -20) grid[step={($(5, 5) - (0, 0)$)}] (60, 100);
\path
(0,0) coordinate (z0)
(10,10) coordinate (z1)
(20,0) coordinate (z2)
(30,10) coordinate (z3)
(40,0) coordinate (z4)
(50,10) coordinate (z5)
(30,90) coordinate (z6)
(0,70) coordinate (z7)
(0,60) coordinate (z8)
;
\draw[closed,black, line width= 3mm] (z0) .. (z1) .. (z2) .. (z3) .. (z4) .. (z5).. (z6).. (z7).. (z8);
\end{tikzpicture}
\end{document}
答案1
这是我的尝试,使用 Ti钾Z 和很多to[out=...,in=...]
s。
\documentclass[border=2mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[thick,line cap=round]
% grid
%\draw[gray] (-5,0) grid[step=0.5] (5,13);
% ghost 'body'
\draw[line width=0.75mm] (0,1.5) to[out=0,in=180] (1.5,0)
to[out=0 ,in=180] (3,2) to[out=0,in=135] (4,1.5)
to[out=-45,in=-45,looseness=2] (4.5,2)
to[out=135,in=270] (3,8)
to[out=90 ,in=90 ,looseness=2.5] (-3,8)
to[out=270,in=45] (-4.5,2)
to[out=225,in=225,looseness=2] (-4,1.5)
to[out=45 ,in=180] (-3,2)
to[out=0 ,in=180] (-1.5,0)
to[out=0 ,in=180] (0,1.5);
% ghost eyes
\foreach\i in {-1,1}
{%
\begin{scope}[shift={(\i-0.3,8.5)},rotate=\i*10]
\fill ellipse (0.3 cm and 0.6 cm);
\end{scope}}
% axis
\draw (-5.5,-1) -- (5.5,-1);
\foreach\i in {-5,...,5}
\draw (\i,-1) --++ (0,-0.2);
\node at (0,-2) {\huge\bfseries Paranormal Distribution};
\end{tikzpicture}
\end{document}
编辑。动画幽灵:
\documentclass {beamer}
\usepackage {tikz}
\setbeamertemplate{navigation symbols}{}
\begin{document}
\begin{frame}
\begin{figure}\centering
\begin{tikzpicture}[thick,line cap=round,scale=0.5]
\useasboundingbox (-8,0) rectangle (8,14);
% fake normal distribution
\foreach\j in {1,...,5}
{%
\pgfmathtruncatemacro\jj{20-\j}
\only<\j,\jj>
{%
\pgfmathsetmacro\y{0.2*(10-\j)}
\draw plot[domain=-8:8,samples=81,smooth] (\x*\y,{13/(1+0.07*\x*\x)});
}
}
% ghost
\foreach\j in {6,...,14}
{%
\only<\j>
{%
\pgfmathsetmacro\y{0.05*abs(10-\j)}
% ghost 'body'
\coordinate (A) at (0,1.5+\y);
\coordinate (B) at (1.5,0);
\coordinate (C) at (3,2+\y);
\coordinate (D) at (4,1.5);
\coordinate (E) at (4.5,2);
\coordinate (F) at (-4.5,2);
\coordinate (G) at (-4,1.5);
\coordinate (H) at (-3,2+\y);
\coordinate (I) at (-1.5,0);
\draw[line width=0.5mm] (A) to[out=0,in=180] (B)
to[out=0 ,in=180] (C) to[out=0,in=135] (D)
to[out=-45,in=-45,looseness=2] (E)
to[out=135,in=270] (3,8)
to[out=90 ,in=90,looseness=2.5] (-3,8)
to[out=270,in=45] (F)
to[out=225,in=225,looseness=2] (G)
to[out=45 ,in=180] (H)
to[out=0 ,in=180] (I)
to[out=0 ,in=180] (A);
% ghost eyes
\foreach\i in {-1,1}
{%
\begin{scope}[shift={(\i-3*\y,8.5)},rotate=\i*10]
\fill ellipse (0.3cm and 0.6cm);
\end{scope}
}
}
}
% axis
\draw (-8.5,-1) -- (8.5,-1);
\foreach\i in {-8,...,8}
\draw (\i,-1) --++ (0,-0.2);
\node at (0,-2) {\huge\bfseries\strut
\only<8-12>{p}%
\only<7-13>{a}%
\only<6-14>{r}%
\only<5-15>{a}%
normal distribution\strut};
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
答案2
答案3
使用纯 tikz 的快速建议:
\documentclass[border=6.66mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[smooth cycle]
\draw[] plot[tension=1]
coordinates{(0,0) (1,1) (2,0) (3,1) (4,0) (4,4) (3,9) (0,2) (0,1)};
%eyes
\draw[fill=black,rotate around={-45:(2.3,7)}] (2.3,7) ellipse (2mm and 3.5mm);
\draw[fill=black,rotate around={-45:(3.3,7)}] (3.3,7) ellipse (2mm and 3.5mm);
%mouth [optional]
\draw[fill=black,rotate around={-10:(3,5)}] (3,5) arc (0:-180:0.5cm and 3mm);
\end{tikzpicture}
\end{document}