Python--seaborn库

一个可视化库seaborn,可以与pandas数据框完美协作。seaborn是建立在matplotlib之上的,我们可以利用matplotlib所学的知识来修改并使用seaborn。


import os
import pandas as pd
import numpy as np
import seaborn as sns
import requests
import matplotlib.pyplot as plt
plt.style.use('ggplot')
%matplotlib inline

PATH = r'C:/Users/Administrator/Desktop/iris/'
r = requests.get('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data')
#print(r.text)
with open(PATH + 'iris.data' , 'w') as f:
    f.write(r.text)
    
os.chdir(PATH)

df = pd.read_csv(PATH + 'iris.data' , names = ['sepal length' , 'sepal width' , 'petal length' , 'petal width' , 'class'])

sns.pairplot(df , hue = "class")

fig , ax= plt.subplots(2 , 2 , figsize = (7 , 7))
sns.set (style = 'white' ,palette = 'muted')
sns.violinplot(x = df['class'] , y = df['sepal length'] , ax = ax[0,0])
sns.violinplot(x = df['class'] , y = df['sepal width'] , ax = ax[0,1])
sns.violinplot(x = df['class'] , y = df['petal length'] , ax = ax[1,0])
sns.violinplot(x = df['class'] , y = df['petal width'] , ax = ax[1,1])
fig.suptitle('Violin Plots', fontsize = 16 , y = 1.03)
for i in ax.flat:
    plt.setp(i.get_xticklabels() , rotation = -90)
fig.tight_layout()

结果如下:



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值