如果您不想使用seaborn
風格,但確實需要一些seaborn功能,您可以使用此以下行(documentation)導入seaborn:
import seaborn.apionly as sns
如果要產生一些情節與seaborn
風格,有些沒有,在同一個腳本中,可以使用seaborn.reset_orig
函數關閉seaborn
風格。
看來做apionly
導入本質上設置reset_orig
自動導入,所以它取決於你,這是你的用例最有用。
下面是matplotlib
默認值,並seaborn
之間切換的示例:
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
# a simple plot function we can reuse (taken from the seaborn tutorial)
def sinplot(flip=1):
x = np.linspace(0, 14, 100)
for i in range(1, 7):
plt.plot(x, np.sin(x + i * .5) * (7 - i) * flip)
sinplot()
# this will have the matplotlib defaults
plt.savefig('seaborn-off.png')
plt.clf()
# now import seaborn
import seaborn as sns
sinplot()
# this will have the seaborn style
plt.savefig('seaborn-on.png')
plt.clf()
# reset rc params to defaults
sns.reset_orig()
sinplot()
# this should look the same as the first plot (seaborn-off.png)
plt.savefig('seaborn-offagain.png')
產生以下三個曲線:
seaborn-off.png:
seaborn-on.png:
seaborn-offagain.png:
來源
2015-10-13 11:22:18
tom
的可能的複製[我如何使用seaborn不改變matplotlib默認值?(http://stackoverflow.com/questions/25393936/how-can -i-use-seaborn-without-changing-the-matplotlib-defaults) – mwaskom
seaborn文檔非常好。這在安裝文檔的開頭部分已經介紹過了:http://stanford.edu/~mwaskom/software/seaborn/installing.html?highlight=apionly#importing-seaborn –
我不確定這是否與問題:它還解決了需要在腳本中動態切換seaborn和matplotlib默認值的問題,這不包括在建議的副本中 – tom