1

I've been using seaborn for some data visualisation, but for some reason the axes and spacing seem a little off. This also happens when I use matplotlib and pandas for data visualisation. I will show an example to illustrate my point:

import seaborn as sns
import matplotlib.pyplot as plt 
plt.style.use('ggplot')
tips = sns.load_dataset('tips') # a dataset 
sns.distplot(tips['total_bill']) # 'total_bill' is a column in the dataset

enter image description here

As you can see, there is a start of a new grid above 0.06 on the y axis and also above 60 on the x axis.

This happens with every plot I do, whether it be a distplot, countplot, boxplot, and I'm not sure why it's happening? I've been learning this through an online course and whenever the instructor runs the code, the figures don't have this problem?

the man
  • 1,131
  • 1
  • 8
  • 19

1 Answers1

2

Similarly to my answer here, you can control this behavior using plt.margins()

Compare this code to yours:

plt.style.use('ggplot')
plt.margins(x=0,y=0)
tips = sns.load_dataset('tips') # a dataset 
sns.distplot(tips['total_bill']) # 'total_bill' is a column in the dataset

enter image description here

If you would like to change this property globally, you can change your rcParams. The relevant keys are axes.xmargin and axes.ymargin

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75