Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 访问Seaborn set_style()中的图例属性_Python_Matplotlib_Seaborn - Fatal编程技术网

Python 访问Seaborn set_style()中的图例属性

Python 访问Seaborn set_style()中的图例属性,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我一直在尝试使用sns.set_style()来限制重复设置绘图属性。 我遇到的问题是,我似乎无法找到如何访问我要修改的所有属性。图例颜色 请参见下面的样式表和打印代码: import seaborn as sns import numpy as np dark_plot_no_tick = { 'axes.facecolor': '#181818', 'legend.facecolor': "white", # still inheriting from figure

我一直在尝试使用
sns.set_style()
来限制重复设置绘图属性。
我遇到的问题是,我似乎无法找到如何访问我要修改的所有属性。图例颜色

请参见下面的样式表和打印代码:

import seaborn as sns
import numpy as np

dark_plot_no_tick = {
    'axes.facecolor': '#181818',
    'legend.facecolor': "white", # still inheriting from figure
    'axes.edgecolor': '1',
    'axes.grid': False,
    'figure.facecolor': '#181818', # Works inline but not saving
    'xtick.bottom': False, # still visible
    'xtick.top': False,
    'ytick.left': False, # still visible
    'ytick.right': False,
    'axes.spines.left': True,
    'axes.spines.bottom': True,
    'axes.spines.right': False,
    'axes.spines.top': False
}

sns.set_style(rc=dark_plot_no_tick)
sns.set_palette(['#5FB7B2'])

fig, ax = plt.pyplot.subplots()
sns.kdeplot(np.random.normal(10, 10, 10_000), label="test", ax=ax)
fig.savefig("test.png");
唯一的问题是legend facecolor是透明的或继承的,我不知道如何在传递给set_style()的样式表中更改它

下面是它现在的样子:

这就是我想要的样子:

编辑:
根据@ImportanceOfBeingErnest的建议,我尝试了以下方法:

import matplotlib 

matplotlib.rcParams["legend.facecolor"] = "white"
matplotlib.rcParams["xtick.bottom"] = False
matplotlib.rcParams["ytick.left"] = False
使用
rcParams
修改
legend.facecolor
有效,而修改
xtick.bottom
ytick.left
无效

也就是说,我仍然希望使用
sns.set_style()
而不是
matplotlib.rcParams
来修改facecolor


此外,我意识到删除记号不是原始问题的一部分,但我将其包括在这里,因为我相信这两个问题可能是由于相同的根本原因造成的。

使用
legend.facecolor
@ImportanceOfBeinger最近我尝试将
legend.facecolor
inherit
更改为一系列内容(例如,值0-1、十六进制颜色代码等),它永远不会工作。您能否检查
plt.rcParams[“legend.facecolor”]=“red”
在脚本中起作用?如果它起作用,则意味着您的样式文件中有错误;因此最好显示问题中的样式文件。@ImportanceOfBeingErnest会以我的生命发誓我曾经尝试过……它是这样工作的,当我使用rc_参数使用
rc={“legend.facecolor”:“white”}
。谢谢!@ImportanceOfBeingErnest这非常奇怪…
c={“legend.facecolor”:“white”}
不再工作,但
plt.rcParams[“legend.facecolor”]=“red”
仍然工作…和
plt.savefig()
fig.savefig()
不一定彼此一致,也不一定在jupyter中呈现什么。我只是遇到了一些奇怪的边缘情况吗?使用
图例.facecolor
@ImportanceOfBeingErnest我尝试过将
图例.facecolor
继承
更改为一系列内容(例如值0-1,十六进制颜色代码等)你能检查一下plt.rcParams[“legend.facecolor”]=“red”吗在脚本中起作用?如果它起作用,则意味着您的样式文件中有错误;因此最好显示问题中的样式文件。@ImportanceOfBeingErnest会以我的生命发誓我曾经尝试过……它是这样工作的,当我使用rc_参数使用
rc={“legend.facecolor”:“white”}
。谢谢!@ImportanceOfBeingErnest这非常奇怪…
c={“legend.facecolor”:“white”}
不再工作,但
plt.rcParams[“legend.facecolor”]=“red”
仍然工作…和
plt.savefig()
fig.savefig()
不一定彼此一致,也不一定在jupyter中呈现什么。我只是遇到了一些奇怪的边缘情况吗?