如果您不想使用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