Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 522
Foad S. Farimani Avatar asked Mar 06 '19 15:03

Foad S. Farimani


2 Answers

Try use this (Python)

# Remove all borders
sns.despine(bottom = True, left = True)
plt.show()
like image 41
Vladimir Gavrysh Avatar answered Nov 24 '22 19:11

Vladimir Gavrysh


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

like image 138
ImportanceOfBeingErnest Avatar answered Nov 24 '22 19:11

ImportanceOfBeingErnest