【发布时间】:2017-11-02 23:31:21
【问题描述】:
我按照 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 保持恒定的颜色显示?谢谢。
【问题讨论】:
-
您引用的示例似乎很混乱。为什么将
matplotlib.pyplot(一个模块)作为参数传递给show()函数?我建议采取不同的方式。
标签: python matplotlib seaborn apache-zeppelin