首页 > 解决方案 > seaborn set style 去掉了despine配置的边框

问题描述

考虑这个情节:

import matplotlib.pyplot as plt
import seaborn as sns

Data = sns.load_dataset("tips")
g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data = Data, legend_out = False, aspect = 2)
g.set(xlabel = "independent", ylabel = "dependent")
sns.despine(fig=None, ax=None, top=False, right=False, left=False, bottom=False, offset=None, trim=False)
plt.show()

在此处输入图像描述

现在,如果我添加设置:

sns.set(rc={'figure.figsize':(10,5)}, font_scale=1.5)
sns.set_style({'axes.facecolor':'white', 'grid.color': '.8', 'font.family':'Times New Roman'})

它删除了我想保留的边框:

在此处输入图像描述

如果您能帮助我了解问题所在以及如何解决,我将不胜感激。

标签: pythonmatplotlibplotseaborn

解决方案


也许你想忽略 seaborn 的样式,直接设置你需要的参数?

import matplotlib.pyplot as plt
import seaborn as sns

rc = {'figure.figsize':(10,5),
      'axes.facecolor':'white',
      'axes.grid' : True,
      'grid.color': '.8',
      'font.family':'Times New Roman',
      'font.size' : 15}
plt.rcParams.update(rc)

Data = sns.load_dataset("tips")
g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data = Data, legend_out = False, aspect = 2)
g.set(xlabel = "independent", ylabel = "dependent")
sns.despine(fig=None, ax=None, top=False, right=False, left=False, bottom=False, offset=None, trim=False)
plt.show()

在此处输入图像描述


推荐阅读