首先,在 Python 中导入所需的库与模块,并对 notebook 环境与图表风格进行初步的设置:
- %matplotlib inline
- import numpy as np
- import matplotlib.pyplot as plt
- plt.style.use('seaborn-white')
- data = np.random.randn(1000)
Matplotlib 中的 hist 函数能够帮助我们很方便的绘制出简单的直方图,下图为我们生成的随机数组 data 中数据的分布情况:
- plt.hist(data);
接下来,看一下在 Python 中像素图的绘制方法:
- mean = [0, 0]
- cov = [[1, 1], [1, 2]]
- x, y = np.random.multivariate_normal(mean, cov, 10000).T
- plt.hist2d(x, y, bins=30, cmap='Blues')
- cb = plt.colorbar()
- cb.set_label('counts in bin')
以上内容转自 数析学院,原文内容较多,需要了解更多的同学可以直接查看原文


雷达卡




京公网安备 11010802022788号







