原文: http://web.stanford.edu/~mwaskom/software/seaborn/tutorial/aesthetics.htmlhtml
第一小部分有人翻譯過了,連接:http://www.javashuo.com/article/p-wkwcncpu-eg.htmlweb
axes_style()
和set_style()
管理圖表樣式Seaborn有五個預設好的主題:darkgrid
, whitegrid
, dark
, white
,和ticks
。它們各自適用於不一樣的應用和我的喜愛。缺省的主題是darkgrid
。如上文提到的,網格讓圖表的佈局成爲了查找大量信息的表格,而且白線灰底讓網絡不會影響表明數據的線的顯示。儘管whitegrid
主題很是簡潔,可是它更適用於數據元素較大的佈局。segmentfault
sns.set_style("whitegrid") data = np.random.normal(size=(20, 6)) + np.arange(6) / 2 sns.boxplot(data=data);
對於大多數佈局,(尤爲是當你主要想要利用圖表來提供給人對於數據模式的印象),網格便不那麼重要了.網絡
sns.set_style("dark") sinplot()
sns.set_style("white") sinplot()
有時你可能想在佈局上添加一些額外的結構,好比說將軸線分割成線段的ticks:dom
sns.set_style("ticks") sinplot()
despine()
移除軸線樣式white
和ticks
均可以經過去除上方和右方沒必要要的軸線來獲得改善. 而這些是不可能在matplotlib裏設置參數作到的,可是你能夠調用seaborn的函數despine()
來去除軸線:函數
sinplot() sns.despine()
有些佈局也能夠經過調整軸線距數據的偏移來改善,這也能在despine()
裏完成.當ticks不能覆蓋軸線的整個範圍時,trim
參數能夠限制顯示的軸線的範圍.佈局
f, ax = plt.subplots() sns.violinplot(data) sns.despine(offset=10, trim=True);
你也可能經過設置另外的參數來控制移除哪條軸線:post
sns.set_style("whitegrid") sns.boxplot(data=data, palette="deep") sns.despine(left=True)
儘管來回切換樣式是很簡單的,可是你也能夠在with
語句裏用axes_style()
函數來臨時設置控制佈局的參數.這也容許你用不一樣的風格來製做圖表:字體
with sns.axes_style("darkgrid"): plt.subplot(211) sinplot() plt.subplot(212) sinplot(-1)
若是你想要自定義seaborn的樣式,你能夠用詞典(dictionary)將一系列控制參數賦值給axes_style()
函數和set_style()
函數的rc
參數裏. 注意你只能經過這種方式重載樣式定義的部分.(可是,更高級的set()
函數能夠處理包含任意matplotlib參數的詞典)spa
若是你想要知道都包含了哪些參數,你能夠調用沒有參數的函數,它會返回當前設置:
sns.axes_style() {'axes.axisbelow': True, 'axes.edgecolor': '.8', 'axes.facecolor': 'white', 'axes.grid': True, 'axes.labelcolor': '.15', 'axes.linewidth': 1.0, 'figure.facecolor': 'white', 'font.family': [u'sans-serif'], 'font.sans-serif': [u'Arial', u'Liberation Sans', u'Bitstream Vera Sans', u'sans-serif'], 'grid.color': '.8', 'grid.linestyle': u'-', 'image.cmap': u'Greys', 'legend.frameon': False, 'legend.numpoints': 1, 'legend.scatterpoints': 1, 'lines.solid_capstyle': u'round', 'text.color': '.15', 'xtick.color': '.15', 'xtick.direction': u'out', 'xtick.major.size': 0.0, 'xtick.minor.size': 0.0, 'ytick.color': '.15', 'ytick.direction': u'out', 'ytick.major.size': 0.0, 'ytick.minor.size': 0.0}
而後你能夠設置這些參數的不一樣版本:
sns.set_style("darkgrid", {"axes.facecolor": ".9"}) sinplot()
plotting_context()
和set_context()
來設置佈局元素的規模佈局元素的規模被獨立的參數集合控制,這能讓你使用相同的代碼獲得不一樣大小的規模合適的佈局
首先讓咱們從新調用set()
函數獲得缺省設置:
sns.set()
有4種預設好的上下文(context),按相對大小排序分別是:paper
, notebook
, talk
,和poster
.缺省的規模是notebook
,上述的全部圖表都是它.
sns.set_context("paper") plt.figure(figsize=(8, 6)) sinplot()
sns.set_context("talk") plt.figure(figsize=(8, 6)) sinplot()
sns.set_context("poster") plt.figure(figsize=(8, 6)) sinplot()
大部分你如今所稽首的樣式函數都應該被轉換成上下文函數.
你能夠調用set_context()
,將上下文的名字看成一個參數傳入,而後你就能夠經過提供一個寫有各項設置值的詞典重載上下文的參數。
在修改上下文時,你也能夠單獨修改字體大小。(更高級的set()
裏也能夠這麼作)
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5}) sinplot()
一樣地(雖然可能沒什麼用),你能夠用with
語句臨時設置圖表的規模。
樣式和上下文均可能經過set()
來快速設置。這個函數也能夠設置缺省的配色方案,不過這將是下一節咱們要詳細講述的。