2014-03-25 31 views
4

我立刻喜歡seaborn的一件事是,它將Matplotlib默認的圖像調色板(imshow,pcolormesh,contourf,...)設置爲我以前從未見過的非常好的一個(黑色 - 藍色 - 綠色 - 棕色 - 粉紅色,紫色,白色):什麼是seaborn 0.2版中圖像的默認調色板?

plt.contourf(np.random.random((20,20))) 

Default contourf plot under seaborn v. 0.2.1

但是,當我從0.21版升級包0.3,這個默認是換到灰階:

Default contourf plot under seaborn v. 0.3

v。0.2.1調用的默認調色板是什麼?如何恢復?

回答

6

在seaborn訴默認調色板。0.2.1是Dave Green's 'cubehelix'並且你可以通過

import seaborn as sns 
sns.set(rc={'image.cmap': 'cubehelix'}) 

A「蠻力」拿回來訴0.3發現這一點的方法是回滾到舊版本並創建一個默認的情節:

img = plt.contourf(np.random.random((20,20))) 
print(img.cmap.name) 

事實上,在seaborn默認是在this file in the seaborn repo定義。查看Matplotlib sample matplotlibrc file也可能有助於找到適合的參數進行調整。

6

只需添加到j08lue的答案,它改變的原因是,它幾乎是不可能選擇一個默認顏色映射適合於所有類型的數據,並有一個壞的彩色地圖可引起lotsofproblems。希望通過將默認地圖設爲灰度地圖,它會鼓勵人們思考他們的數據並選擇正確的地圖。

通過的方式,用色彩映射圖將採取cmap關鍵字參數都(最?)matplotlib功能,即plt.contourf(x, y, z, cmap="cubehelix")會工作。

+0

謝謝你解釋,邁克爾,這實際上是一個非常好的舉措。 – j08lue

相關問題