主流图表分析(seaborn常用的10)
内置示例数据集
seaborn内置了十几个示例数据集,通过load_dataset函数可以调用。
其中包括常见的泰坦尼克、鸢尾花等经典数据集。
#查看数据集种类
importseabornassns
sns.get_dataset_names()
importseabornassns
#导出鸢尾花数据集
data=sns.load_dataset('iris')
data.head()
1、散点图
函数sns.scatterplot
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
#小费数据集
tips=sns.load_dataset('tips')
ax=sns.scatterplot(x='total_bill',y='tip',data=tips)
plt.show()
2、条形图
函数sns.barplot
显示数据平均值和置信区间
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
#小费数据集
tips=sns.load_dataset("tips")
ax=sns.barplot(x="day",y="total_bill",data=tips)
plt.show()
3、线型图
函数sns.lineplot
绘制折线图和置信区间
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
fmri=sns.load_dataset("fmri")
ax=sns.lineplot(x="timepoint",y="signal",data=fmri)
plt.show()
4、箱线图
函数seaborn.boxplot
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
tips=sns.load_dataset("tips")
ax=sns.boxplot(x="day",y="total_bill",data=tips)
plt.show()
5、直方图
函数seaborn.distplot
importseabornassns
importnumpyasnp
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
np.random.seed(0)
x=np.random.randn(1000)
ax=sns.distplot(x)
plt.show()
6、热力图
函数seaborn.heatmap
importnumpyasnp
np.random.seed(0)
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
uniform_data=np.random.rand(10,12)
ax=sns.heatmap(uniform_data)
plt.show()
7、散点图矩阵
函数sns.pairplot
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
iris=sns.load_dataset("iris")
ax=sns.pairplot(iris)
plt.show()
8、分类散点图
函数seaborn.catplot
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
exercise=sns.load_dataset("exercise")
ax=sns.catplot(x="time",y="pulse",hue="kind",data=exercise)\
plt.show()
9、计数条形图
函数seaborn.countplot
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
titanic=sns.load_dataset("titanic")
ax=sns.countplot(x="class",data=titanic)
plt.show()
10、回归图
函数 seaborn.lmplot
绘制散点及回归图
importseabornassns
sns.set()
importmatplotlib.pyplotasplt
%matplotlibinline
tips=sns.load_dataset("tips")
ax=sns.lmplot(x="total_bill",y="tip",data=tips)
plt.show()
,
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com