2017-06-01 57 views
0

我遵循here的设置使matplotlib/seaborn可用于在Zeppelin中显示。然而,用下面的代码:Seaborn为不同的运行显示不同的颜色

%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) 

奇怪的是,所显示的图中示出了所希望的颜色lightblue第一次运行该代码,但将显示不同的颜色,如果我执行相同的一段代码。有没有办法强制seaborn保持不变的颜色显示?谢谢。

+0

你引用的例子看起来很混乱。为什么它将'matplotlib.pyplot'(一个模块)作为参数传递给'show()'函数?我建议以这种不同的方式。 – mwaskom

回答

1

这并不完全清楚“再次运行”是什么意思。

但是,您可能会尝试在再次运行之前实际关闭该图。例如。

plt.close("all") 

为了确保创建一个每次都应该具有相同默认颜色的新图形。

相关问题