一、问题分析
1.1 问题描述
Understanding Distributions Through Sampling
To complete this assignment, create a code cell that:
- Creates a number of subplots using the
pyplot subplots
ormatplotlib gridspec
functionality. - Creates an animation, pulling between 100 and 1000 samples from each of the random variables (
x1
,x2
,x3
,x4
) for each plot and plotting this as we did in the lecture on animation. - Bonus: looking into matplotlib widgets and adding a widget which allows for parameterization of the distributions behind the sampling animations.
Tips:
- Before you start, think about the different ways you can create this visualization to be as interesting and effective as possible.
- Take a look at the histograms below to get an idea of what the random variables look like, as well as their positioning with respect to one another. This is just a guide, so be creative in how you lay things out!
- Try to keep the length of your animation reasonable (roughly between 10 and 30 seconds).
1.2 问题分析
将直方图的生成过程可视化。
二、代码详情
2.1 代码
import matplotlib.pyplot as plt
import numpy as np
%matplotlib notebook
#生成数据
x1 = np.random.normal(-2.5, 1, 10000)
x2 = np.random.gamma(2, 1.5, 10000)
x3 = np.random.exponential(2, 10000)+7
x4 = np.random.uniform(14,20, 10000)
#做直方图
plt.figure(figsize=(9,3))
plt.hist(x1, density=True, bins=20, alpha=0.5)
plt.hist(x2,</