Search code examples
pythonseabornfacet-grid

Seaborn set style removes the border configured by despine


Consider this plot:

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

enter image description here

Now if I add the settings:

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'})

It removes the border which I want to keep:

enter image description here

I would appreciate if you could help me know what is th eproblem and how I can fix it.


Solution

  • Maybe you want to ignore seaborn's styling and just set the parameters you need directly?

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

    enter image description here