【问题标题】:Seaborn displays different color for different runSeaborn 为不同的跑步显示不同的颜色
【发布时间】: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


【解决方案1】:

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

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

plt.close("all")

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

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多