18-12-9-視覺化庫Seaborn學習筆記(五:category-分類)
阿新 • • 發佈:2018-12-17
資料匯入
#!/usr/bin/python # -*- coding: UTF-8 -*- # %matplotlib inline import numpy as np import pandas as pd import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sns sns.set(style="whitegrid", color_codes=True) np.random.seed(sum(map(ord, "categorical"))) titanic = sns.load_dataset("titanic") tips = sns.load_dataset("tips")
sns.stripplot(x="day", y="total_bill", data=tips);
jitter去重疊
重疊是很常見的現象,但是重疊影響觀察資料的量
sns.stripplot(x="day", y="total_bill", data=tips, jitter=True)
使用sns.swarmplot()生成樹狀散點圖
sns.swarmplot(x="day", y="total_bill", data=tips)
sns.swarmplot()加入hue="sex"
sns.swarmplot(x="day", y="total_bill", hue="sex",data=tips)
sns.swarmplot()加入調色盤
colors = ["windows blue", "amber", "greyish", "faded green", "dusty purple"]
sns.swarmplot(x="day", y="total_bill", hue="sex",data=tips, palette=sns.xkcd_palette(colors))
sns.swarmplot(x="total_bill", y="day", hue="time", data=tips);
盒圖-sns.boxplot()
- IQR即統計學概念四分位距,第一/四分位與第三/四分位之間的距離
- N = 1.5IQR 如果一個值>Q3+N或 < Q1-N,則為離群點
sns.boxplot(x="day", y="total_bill", hue="time", data=tips);
鋼琴圖-sns.violinplot()
sns.violinplot(x="total_bill", y="day", hue="time", data=tips);
sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True);
sns.violinplot(x="day", y="total_bill", data=tips, inner=None)
sns.swarmplot(x="day", y="total_bill", data=tips, color="w", alpha=.5)
顯示值的集中趨勢可以用條形圖sns.barplot()
sns.barplot(x="sex", y="survived", hue="class", data=titanic);
sns.barplot(x="class", y="survived", hue="sex", data=titanic);
點圖sns.pointplot();
sns.pointplot(x="sex", y="survived", hue="class", data=titanic);
sns.pointplot(x="class", y="survived", hue="sex", data=titanic,
palette={"male": "g", "female": "m"},
markers=["^", "o"], linestyles=["-", "--"]);
寬形資料sns.boxplot();
iris = sns.load_dataset("iris")
sns.boxplot(data=iris,orient="h");
多層面板分類圖sns.factorplot() -- @突出標識@
sns.factorplot(x="day", y="total_bill", hue="smoker", data=tips)
sns.factorplot(x="day", y="total_bill", hue="smoker", data=tips, kind="bar")
sns.factorplot(x="day", y="total_bill", hue="smoker",
col="time", data=tips, kind="swarm")
sns.factorplot(x="time", y="total_bill", hue="smoker",
col="day", data=tips, kind="box", size=4, aspect=.5)
Parameters:引數介紹 -- @突出標識@
- x,y,hue 資料集變數 變數名
- date 資料集 資料集名
- row,col 更多分類變數進行平鋪顯示 變數名
- col_wrap 每行的最高平鋪數 整數
- estimator 在每個分類中進行向量到標量的對映 向量
- ci 置信區間 浮點數或None
- n_boot 計算置信區間時使用的引導迭代次數 整數
- units 取樣單元的識別符號,用於執行多級引導和重複測量設計 資料變數或向量資料
- order, hue_order 對應排序列表 字串列表
- row_order, col_order 對應排序列表 字串列表
- kind : 可選:point 預設, bar 柱形圖, count 頻次, box 箱體, violin 提琴, strip 散點,swarm 分散點 size 每個面的高度(英寸) 標量 aspect 縱橫比 標量 orient 方向 "v"/"h" color 顏色 matplotlib顏色 palette 調色盤 seaborn顏色色板或字典 legend hue的資訊面板 True/False legend_out 是否擴充套件圖形,並將資訊框繪製在中心右邊 True/False share{x,y} 共享軸線 True/False