秦皇岛建网站公司,wordpress音乐门户主题,网站制作与管理技术标准实训教程,精密导航1、简介
#xff08;1#xff09;高级接口#xff1a;Seaborn 提供了一组高级函数和方法#xff0c;可以使得创建常见的统计图表变得简单#xff0c;例如散点图、线性回归图、箱线图、直方图、核密度估计图、热图等等。无需像 Matplotlib 一样写大量的代码#xff1b;
…1、简介
1高级接口Seaborn 提供了一组高级函数和方法可以使得创建常见的统计图表变得简单例如散点图、线性回归图、箱线图、直方图、核密度估计图、热图等等。无需像 Matplotlib 一样写大量的代码
2置数据集Seaborn 包含了一些内置的示例数据集这些数据集可以用于练习和演示。这些数据集通常与示例图表一起使用以帮助用户更好地理解如何使用 Seaborn 创建可视化。
3统计图表Seaborn 支持许多常用的统计图表类型如散点图、折线图、条形图、箱线图、热图、小提琴图、分类散点图、成对关系图等。这些图表可以用于分析数据的分布、趋势、关系等方面。
4配色方案Seaborn 提供了一组美观的默认配色方案使图表更具吸引力。此外还可以轻松自定义配色方案以满足特定需求。
5高级统计功能Seaborn 提供了用于绘制统计摘要信息的函数例如回归线、置信区间、误差棒图等。这些功能有助于更深入地理解数据。
6对 Pandas 数据框的支持Seaborn 可以与 Pandas 数据框无缝集成使数据的导入、转换和可视化变得更加方便。
7主题和风格Seaborn 允许用户选择不同的图表主题和样式以满足不同的审美和出版需求。
2、catplot
1使用sns.catplot函数并将kind参数设置为bar。
2创建的 catplot 图x轴表示不同的物种speciesy轴表示花瓣长度petal_length并绘制了各个物种的平均花瓣长度的barplots。
import seaborn as sns
import matplotlib.pyplot as plt# 加载Iris数据集
iris sns.load_dataset(iris)# 创建catplot并绘制barplots
sns.catplot(xspecies, ypetal_length, datairis, kindbar)
plt.xlabel(Species)
plt.ylabel(Petal Length)
plt.title(Barplots of Petal Length by Species)
plt.show()
3、violinplot
1使用sns.violinplot函数
2其中x轴表示不同的物种speciesy轴表示萼片长度sepal_length
import seaborn as sns
import matplotlib.pyplot as plt# 加载Iris数据集
iris sns.load_dataset(iris)# 创建violinplot
sns.violinplot(xspecies, ysepal_length, datairis)
plt.title(Violin Plot of Sepal Length by Species)
plt.xlabel(Species)
plt.ylabel(Sepal Length)
plt.show()
4、histplot
1使用sns.histplot函数
2其中 x 轴表示萼片长度sepal_lengthy 轴表示频率出现次数
import seaborn as sns
import matplotlib.pyplot as plt# 加载Iris数据集
iris sns.load_dataset(iris)# 创建histplot
sns.histplot(datairis, xsepal_length, huespecies, bins10, kdeTrue)
plt.title(Histogram of Sepal Length by Species)
plt.xlabel(Sepal Length)
plt.ylabel(Frequency)
plt.legend(titleSpecies)
plt.show()
5、jointplot
1使用sns.jointplot函数
2 x 轴表示萼片长度sepal_lengthy 轴表示萼片宽度sepal_width
import seaborn as sns
import matplotlib.pyplot as plt# 加载Iris数据集
iris sns.load_dataset(iris)# 创建jointplot
sns.jointplot(datairis, xsepal_length, ysepal_width, kindscatter)
plt.xlabel(Sepal Length)
plt.ylabel(Sepal Width)
plt.show() 6、heatmap
1使用sns.heatmap函数
2首先使用corr()函数计算了Iris数据集中数值特征之间的相关性矩阵。然后使用sns.heatmap来绘制相关性热图其中annotTrue表示在热图中显示数值标签cmap参数用于指定颜色地图linewidths参数用于指定单元格之间的边框宽度
import seaborn as sns
import matplotlib.pyplot as plt# 加载Iris数据集
iris sns.load_dataset(iris)# 计算相关性矩阵
correlation_matrix iris.corr()# 创建热图
sns.heatmap(correlation_matrix, annotTrue, cmapcoolwarm, linewidths0.5)
plt.title(Correlation Heatmap of Iris Dataset)
plt.show()
7、lineplot
1使用sns.lineplot函数
2 lineplot用于显示两个连续变量之间的趋势或关系。示例绘制了萼片长度sepal_length与萼片宽度sepal_width之间的线图并使用hue参数将数据按物种分组以在同一图中显示不同物种的趋势。
import seaborn as sns
import matplotlib.pyplot as plt# 加载Iris数据集
iris sns.load_dataset(iris)# 创建lineplot
sns.lineplot(datairis, xsepal_length, ysepal_width, huespecies)
plt.xlabel(Sepal Length)
plt.ylabel(Sepal Width)
plt.title(Line Plot of Sepal Length vs. Sepal Width by Species)
plt.show()
8、boxplot
1使用sns.boxplot函数
2boxplot通常用于可视化数据的分布和离群值。创建的 boxplot 图x轴表示不同的物种speciesy轴表示萼片长度sepal_length。boxplot图展示了每个物种的萼片长度分布包括中位数、四分位数和离群值。
import seaborn as sns
import matplotlib.pyplot as plt# 加载Iris数据集
iris sns.load_dataset(iris)# 创建boxplot
sns.boxplot(xspecies, ysepal_length, datairis)
plt.xlabel(Species)
plt.ylabel(Sepal Length)
plt.title(Box Plot of Sepal Length by Species)
plt.show() 觉得文章对自己有用的宝子可以收藏文章并给小编点个赞
想了解更多统计学、数据分析、数据开发、机器学习算法、深度学习等有关知识的宝子们可以关注小编希望以后我们一起成长