NumPy 教程
/ Seaborn
Seaborn
使用 Seaborn 可视化分布
Seaborn 是一个使用 Matplotlib 来绘制图表的库。它将用于可视化随机分布。

安装 Seaborn
如果系统上已安装 Python 和 PIP,请使用以下命令安装 Seaborn:
C:\Users\Your Name>pip install seaborn
如果您使用 Jupyter,请使用以下命令安装 Seaborn:
C:\Users\Your Name>!pip install seaborn
分布图(Distplot)
Distplot 代表分布图,它以数组作为输入,并绘制与数组中点的分布相对应的曲线。
导入 Matplotlib
使用以下语句在代码中导入 Matplotlib 模块的 pyplot 对象:
import matplotlib.pyplot as plt
您可以在我们的 Matplotlib 教程中了解 Matplotlib 模块。
导入 Seaborn
使用以下语句在代码中导入 Seaborn 模块:
import seaborn as sns
绘制分布图
实例
import matplotlib.pyplot as plt import seaborn as sns sns.distplot([0, 1, 2, 3, 4, 5]) plt.show()
绘制没有直方图的 Distplot
实例
import matplotlib.pyplot as plt import seaborn as sns sns.displot([0, 1, 2, 3, 4, 5], kind="kde") plt.show()
注意:在本教程中,我们将使用 sns.distplot(arr, kind="kde")
来可视化随机分布。