seaborn.set_theme#

seaborn.set_theme(context='notebook', style='darkgrid', palette='deep', font='sans-serif', font_scale=1, color_codes=True, rc=None)#

為所有 matplotlib 和 seaborn 圖表設定視覺主題的各個方面。

此函式使用 matplotlib rcParams 系統更改所有圖表的全域預設值。主題設定分解為多個不同的參數值集合。

這些選項在美學色彩調色盤教學中進行了說明。

參數:
context字串或字典

縮放參數,請參閱 plotting_context()

style字串或字典

軸樣式參數,請參閱 axes_style()

palette字串或序列

色彩調色盤,請參閱 color_palette()

font字串

字型系列,請參閱 matplotlib 字型管理員。

font_scale浮點數,可選

獨立縮放字型元素大小的單獨縮放因子。

color_codes布林值

如果為 Truepalette 是 seaborn 調色盤,則將速記色彩代碼(例如「b」、「g」、「r」等)重新對應到此調色盤的色彩。

rc字典或 None

rc 參數對應的字典,用於覆寫以上內容。

範例

預設情況下,seaborn 圖表將使用 matplotlib rcParams 的目前值繪製

sns.barplot(x=["A", "B", "C"], y=[1, 3, 2])
../_images/set_theme_1_0.png

呼叫此函式時不帶任何引數將啟動 seaborn 的「預設」主題

sns.set_theme()
sns.barplot(x=["A", "B", "C"], y=[1, 3, 2])
../_images/set_theme_3_0.png

請注意,這將對所有 matplotlib 圖表生效,包括未使用 seaborn 製作的圖表

plt.bar(["A", "B", "C"], [1, 3, 2])
../_images/set_theme_5_0.png

seaborn 主題分解為多個不同的參數集合,您可以獨立控制這些參數

sns.set_theme(style="whitegrid", palette="pastel")
sns.barplot(x=["A", "B", "C"], y=[1, 3, 2])
../_images/set_theme_7_0.png

傳遞 None 可保留給定參數集合的目前值

sns.set_theme(style="white", palette=None)
sns.barplot(x=["A", "B", "C"], y=[1, 3, 2])
../_images/set_theme_9_0.png

您也可以覆寫任何 seaborn 參數或定義屬於 matplotlib rc 系統但不包含在 seaborn 主題中的其他參數

custom_params = {"axes.spines.right": False, "axes.spines.top": False}
sns.set_theme(style="ticks", rc=custom_params)
sns.barplot(x=["A", "B", "C"], y=[1, 3, 2])
../_images/set_theme_11_0.png