目錄
1.Seaborn風(fēng)格設(shè)置
1.1 主題設(shè)置
1.2 軸線設(shè)置
?1.3?移除軸線
?1.4 使用字典傳遞函數(shù)
?2.設(shè)置繪圖元素比例
2.1 設(shè)置繪圖元素比例paper
2.2 設(shè)置繪圖元素比例poster
2.3 設(shè)置繪圖元素比例notebook
Seaborn將Matplotlib的參數(shù)劃分為兩個(gè)獨(dú)立的組合,第一組用于設(shè)置繪圖的外觀風(fēng)格,第二組用于將繪圖的各種元素按比例縮放。控制這些參數(shù)的接口主要有兩對(duì)方法:
- 控制風(fēng)格:axes_style(),set_style();
- 縮放繪圖:plotting_context(),set_context()。
1.Seaborn風(fēng)格設(shè)置
1.1 主題設(shè)置
set_style()用于設(shè)置主題,Seaborn有5個(gè)預(yù)設(shè)的主題,以下是這5個(gè)預(yù)設(shè)主題的簡(jiǎn)要介紹:
-
“darkgrid”:深色網(wǎng)格主題,具有灰色背景和暗色網(wǎng)格線,在繪制時(shí)可以提供良好的對(duì)比度和可讀性。
-
“whitegrid”:白色網(wǎng)格主題,類似于"darkgrid",但背景是白色的,適用于需要明亮背景的情況。
-
“dark”:深色背景主題,具有漆黑的背景和淺色文本,適用于在黑暗環(huán)境中查看圖形。
-
“white”:白色背景主題,與"dark"相反,具有白色背景和深色文本,適用于明亮的環(huán)境。
-
“ticks”:軸刻度線主題,具有刻度線和標(biāo)簽,適用于顯示軸上的刻度線和標(biāo)簽。
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
def sinplot(flip = 2):
x = np.linspace(0,20, 50)
for i in range(1,5):
plt.plot(x, np.cos(x + i * 0.8) * (9 - 2*i) * flip)
sinplot()
sns.set_style("white") #設(shè)置主題
sinplot()
結(jié)果圖:
1.2 軸線設(shè)置
sinplot()
sns.despine(offset = 20, trim = True)
?sns.despine()
是seaborn庫(kù)中的一個(gè)函數(shù),用于移除繪圖中的軸線(spines)。該函數(shù)提供了一些參數(shù)來控制軸線的移除方式。其中,offset
參數(shù)用于調(diào)整軸線和繪圖區(qū)域的距離,trim
參數(shù)用于控制是否根據(jù)實(shí)際的數(shù)據(jù)范圍截取軸線。
結(jié)果圖:?
?1.3?移除軸線
sinplot()
sns.despine(left = True,bottom = True)
結(jié)果圖:
?1.4 使用字典傳遞函數(shù)
sns.set_style("darkgrid", {"axes.facecolor": ".9"})
sinplot()
結(jié)果圖:
?2.設(shè)置繪圖元素比例
2.1 設(shè)置繪圖元素比例paper
sns.set_context("paper")
sinplot()
結(jié)果圖:
2.2 設(shè)置繪圖元素比例poster
sns.set_context("poster")
sinplot()
結(jié)果圖:
2.3 設(shè)置繪圖元素比例notebook
sns.set_context("notebook", font_scale = 1.8, rc = {"lines.linewidth": 1.5})
sinplot()
結(jié)果圖:
?文章來源地址http://www.zghlxwxcb.cn/news/detail-660907.html
?文章來源:http://www.zghlxwxcb.cn/news/detail-660907.html
?
到了這里,關(guān)于Seaborn數(shù)據(jù)可視化(二)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!