主页 > 开源代码  > 

Seaborn知识总结

Seaborn知识总结
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轴表示不同的物种(species),y轴表示花瓣长度(petal_length),并绘制了各个物种的平均花瓣长度的barplots。

import seaborn as sns import matplotlib.pyplot as plt # 加载Iris数据集 iris = sns.load_dataset("iris") # 创建catplot并绘制barplots sns.catplot(x="species", y="petal_length", data=iris, kind="bar") plt.xlabel("Species") plt.ylabel("Petal Length") plt.title("Barplots of Petal Length by Species") plt.show() 3、violinplot

(1)使用sns.violinplot函数

(2)其中x轴表示不同的物种(species),y轴表示萼片长度(sepal_length)

import seaborn as sns import matplotlib.pyplot as plt # 加载Iris数据集 iris = sns.load_dataset("iris") # 创建violinplot sns.violinplot(x="species", y="sepal_length", data=iris) 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_length),y 轴表示频率(出现次数)

import seaborn as sns import matplotlib.pyplot as plt # 加载Iris数据集 iris = sns.load_dataset("iris") # 创建histplot sns.histplot(data=iris, x="sepal_length", hue="species", bins=10, kde=True) plt.title("Histogram of Sepal Length by Species") plt.xlabel("Sepal Length") plt.ylabel("Frequency") plt.legend(title="Species") plt.show() 5、jointplot

(1)使用sns.jointplot函数

(2) x 轴表示萼片长度(sepal_length),y 轴表示萼片宽度(sepal_width)

import seaborn as sns import matplotlib.pyplot as plt # 加载Iris数据集 iris = sns.load_dataset("iris") # 创建jointplot sns.jointplot(data=iris, x="sepal_length", y="sepal_width", kind="scatter") plt.xlabel("Sepal Length") plt.ylabel("Sepal Width") plt.show()  6、heatmap

(1)使用sns.heatmap函数

(2)首先,使用corr()函数计算了Iris数据集中数值特征之间的相关性矩阵。然后,使用sns.heatmap来绘制相关性热图,其中annot=True表示在热图中显示数值标签,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, annot=True, cmap="coolwarm", linewidths=0.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(data=iris, x="sepal_length", y="sepal_width", hue="species") 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函数

(2)boxplot通常用于可视化数据的分布和离群值。创建的 boxplot 图,x轴表示不同的物种(species),y轴表示萼片长度(sepal_length)。boxplot图展示了每个物种的萼片长度分布,包括中位数、四分位数和离群值。

import seaborn as sns import matplotlib.pyplot as plt # 加载Iris数据集 iris = sns.load_dataset("iris") # 创建boxplot sns.boxplot(x="species", y="sepal_length", data=iris) plt.xlabel("Species") plt.ylabel("Sepal Length") plt.title("Box Plot of Sepal Length by Species") plt.show()

 

 


👏觉得文章对自己有用的宝子可以收藏文章并给小编点个赞!

👏想了解更多统计学、数据分析、数据开发、机器学习算法、深度学习等有关知识的宝子们,可以关注小编,希望以后我们一起成长!

标签:

Seaborn知识总结由讯客互联开源代码栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“Seaborn知识总结