Source: CSDN Blog

CSDN Blog 数据分析之seaborn画图

一、数据导入In [2]:import pandas from pandas import set_option #括号里面直接指定了数据的来源,当然你也可以按照老师视频中所讲授的来操作 iris = pandas.read_csv('http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data') iris.columns=['sepal_length','sepal_width','petal_length','petal_width','species'] 导入seabornIn [5]:import matplotlib.pyplot as plt import seaborn as sns #要注意的是一旦导入了seaborn,matplotlib的默认作图风格就会被覆盖成seaborn的格式 让图片在notebook里面更加灵活In [11]:%matplotlib notebook中文显示In [4]:plt.rc('font', family='SimHei', size=8) 二、条形图In [10]:sns.barplot(x="sepal_length",y="species",data=iris) Out[10]:<matplotlib.axes._subplots.AxesSubplot at 0x8fa54b0>三、直方图In [11]:sns.distplot(iris["sepal_length"]) Out[11]:<matplotlib.axes._subplots.AxesSubplot at 0x8fb49b0>三、折线图In [12]:sns.pointplot(x="sepal_length",y="species",data=iris) Out[12]:<matplotlib.axes._subplots.AxesSubplot at 0xb1f7770>四、散点图普通散点图In [19]:sns.stripplot(x="sepal_length", y="species", data=iris, jitter=True, edgecolor="gray") Out[19]:<matplotlib.axes._subplots.AxesSubplot at 0xb97c050>带回归线的散点图In [15]:sns.regplot(x="sepal_length",y="sepal_length",data=iris) Out[15]:<matplotlib.axes._subplots.AxesSubplot at 0xb62a370>五、箱形图In [20]:sns.boxplot(x="sepal_length",y="species",data=iris) Out[20]:<matplotlib.axes._subplots.AxesSubplot at 0xb97c950>六、小提琴图In [22]:sns.violinplot(x="sepal_length", y="species", data=iris, size=6) Out[22]:<matplotlib.axes._subplots.AxesSubplot at 0xbb69450>七、pairplotIn [61]:sns.pairplot(iris,hue="species",size=2) Out[61]:<seaborn.axisgrid.PairGrid at 0x2593e850>显示kdeIn [55]:sns.pairplot(iris,hue="species", size=2, diag_kind="kde") Out[55]:<seaborn.axisgrid.PairGrid at 0x23491b30>八、热点图In [8]:iris_nospecies = iris.pop("species") sns.heatmap(iris) # Out[8]:<matplotlib.axes._subplots.AxesSubplot at 0xb2b0730>In [9]:plt.show() In [12]:sns.clustermap(iris, fmt="d",cmap='YlGnBu',figsize=(6,9)) Out[12]:<seaborn.matrix.ClusterGrid at 0xe6675f0>作者:u013584315 发表于2018/1/4 22:16:59 原文链接阅读:65 评论:0 查看评论

Read full article »
Est. Annual Revenue
$25-100M
Est. Employees
100-250
CEO Avatar

CEO

Update CEO

CEO Approval Rating

- -/100

Read more