Seaborn 为不同的 运行 显示不同的颜色
Seaborn displays different color for different run
我按照 here 中的设置使 matplotlib/seaborn 可以在 Zeppelin 中显示。但是,使用以下代码:
%python
import seaborn as sns
import matplotlib
import numpy as np
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.rcdefaults()
import StringIO
def show(p):
img = StringIO.StringIO()
p.savefig(img, format='svg')
img.seek(0)
print "%html <div style='width:600px'>" + img.buf + "</div>"
""" Prepare your plot here ... """
# Use the custom show function instead of plt.show()
x = np.random.randn(100)
ax = sns.distplot(x)
show(sns.plt)
奇怪的是,我第一次 运行 代码时显示的图形显示所需的淡蓝色,但如果我执行相同的代码段,将显示不同的颜色。有没有办法强制 seaborn 保持显示颜色不变?谢谢
"running a second time" 的含义并不完全清楚。
不过,您可以尝试在 运行 之前再次关闭图形。例如
plt.close("all")
为了确保,创建了一个新图形,每次都应具有相同的默认颜色。
我按照 here 中的设置使 matplotlib/seaborn 可以在 Zeppelin 中显示。但是,使用以下代码:
%python
import seaborn as sns
import matplotlib
import numpy as np
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.rcdefaults()
import StringIO
def show(p):
img = StringIO.StringIO()
p.savefig(img, format='svg')
img.seek(0)
print "%html <div style='width:600px'>" + img.buf + "</div>"
""" Prepare your plot here ... """
# Use the custom show function instead of plt.show()
x = np.random.randn(100)
ax = sns.distplot(x)
show(sns.plt)
奇怪的是,我第一次 运行 代码时显示的图形显示所需的淡蓝色,但如果我执行相同的代码段,将显示不同的颜色。有没有办法强制 seaborn 保持显示颜色不变?谢谢
"running a second time" 的含义并不完全清楚。
不过,您可以尝试在 运行 之前再次关闭图形。例如
plt.close("all")
为了确保,创建了一个新图形,每次都应具有相同的默认颜色。