前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,著作權歸原作者所有,如有問題請及時聯系我們以作處理,
以下文章來源于Python學習與資料挖掘,作者:喜歡就關注呀
提到Python的圖形可視化庫,估計你會想到Matplotlib、pyechart、Plotly等,但 Seaborn 卻相對低調了許多,最近在做可視化作圖中,發現 Seaborn 許多復雜的圖形只需一行代碼就可以搞定,將作圖做到極致簡潔,不愧是一款低調卻非常有實力的可視化庫,
Seaborn 是什么
Seaborn 是一個基于matplotlib的高級可視化效果庫,主要針對資料挖掘和機器學習中的變數特征選取,Seaborn 可以用短小的代碼去繪制描述更多維度資料的可視化效果圖,即便是沒有什么基礎的人,也可以通過極簡的代碼,做出具有分析價值而又十分美觀的圖形,
官方鏈接為: Seaborn官方鏈接[1]
Seaborn 提供的功能如下:
?面向資料集的API,用于檢查多個變數之間的關系?專門支持使用分類變數顯示觀察結果或匯總統計資訊?可視化單變數或雙變數分布以及在資料子集之間進行比較的選項?不同種類因變數的線性回歸模型的自動估計和繪圖?用于構造多圖網格的高級抽象,可讓您輕松構建復雜的可視化?帶有幾個內置主題的 matplotlib圖形樣式的精確控制?選擇能夠忠實顯示資料中圖案的調色板的工具
seaborn優點
優點
?簡化了復雜資料集的表示;?可以輕松構建復雜的可視化,簡潔的控制matplotlib圖形樣式與幾個內置主題;?seaborn不可以替代matplotlib,而是matplotlib的很好補充;?對于初學者來說容易上手,具有極簡模式;
圖列展示
1、散點圖矩陣
sns.pairplot(iris,hue="species", palette="Set2", diag_kind="kde", height=2.5)
2、小提琴圖
sns.violinplot(x="day", y="total_bill", hue="smoker",split=True, inner="quart",palette={"Yes": "y", "No": "b"},data=https://www.cnblogs.com/hhh188764/p/tips)
3、箱線圖
sns.catplot(x="color", y="price", kind="boxen",data=https://www.cnblogs.com/hhh188764/p/diamonds.sort_values("color"));
4、線性圖
# shared across the facets
palette = dict(zip(dots.coherence.unique(),sns.color_palette("rocket_r", 6)))
# Plot the lines on two facets
sns.relplot(x="time", y="firing_rate",hue="coherence", size="choice", col="align",size_order=["T1", "T2"], palette=palette,height=5, aspect=.75, facet_kws=dict(sharex=False),kind="line", legend="full", data=https://www.cnblogs.com/hhh188764/p/dots)
5、自定義投影的FacetGrid
import numpy as np
import pandas as pd
import seaborn as sns
sns.set()
# Generate an example radial datast
r = np.linspace(0, 10, num=100)
df = pd.DataFrame({'r': r, 'slow': r, 'medium': 2 * r, 'fast': 4 * r})
# Convert the dataframe to long-form or "tidy" format
df = pd.melt(df, id_vars=['r'], var_name='speed', value_name='theta')
# Set up a grid of axes with a polar projection
g = sns.FacetGrid(df, col="speed", hue="speed",subplot_kws=dict(projection='polar'), height=4.5,sharex=False, sharey=False, despine=False)
# Draw a scatterplot onto each axes in the grid
g.map(sns.scatterplot, "theta", "r")
6、樹形圖
import pandas as pd
import seaborn as sns
sns.set()
# Load the brain networks example dataset
df = sns.load_dataset("brain_networks", header=[0, 1, 2], index_col=0)
# Select a subset of the networks
used_networks = [1, 5, 6, 7, 8, 12, 13, 17]
used_columns = (df.columns.get_level_values("network")
.astype(int)
.isin(used_networks))
df = df.loc[:, used_columns]
# Create a categorical palette to identify the networks
network_pal = sns.husl_palette(8, s=.45)
network_lut = dict(zip(map(str, used_networks), network_pal))
# Convert the palette to vectors that will be drawn on the side of the matrix
networks = df.columns.get_level_values("network")
network_colors = pd.Series(networks, index=df.columns).map(network_lut)
# Draw the full plot
sns.clustermap(df.corr(), center=0, cmap="vlag",row_colors=network_colors, col_colors=network_colors,linewidths=.75, figsize=(13, 13))
PS:如有需要Python學習資料的小伙伴可以加下方的群去找免費管理員領取
可以免費領取原始碼、專案實戰視頻、PDF檔案等
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/20995.html
標籤:Python
上一篇:并發編程——IO模型(重點)
下一篇:python基礎二
