0

I have used the following code to set xticks in seaborn but this is not working. My xticks labels are coming from a list and they are already sorted correctly.

[i[0] for i in jobs]

['admin.',
 'blue-collar',
 'entrepreneur',
 'housemaid',
 'management',
 'retired',
 'self-employed',
 'services',
 'student',
 'technician',
 'unemployed',
 'unknown']

plt.figure(figsize=(7,3))
g = sns.countplot(x='job', y=None, data=df)
plt.title("Attempts by Job")
g.set(xticks=[i[0] for i in jobs])
#plt.xticks = jobs
plt.show()

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/category.py in convert(value, unit, axis)
     63 
     64         # force an update so it also does type checking
---> 65         unit.update(values)
     66 
     67         str2idx = np.vectorize(unit._mapping.__getitem__,

AttributeError: 'NoneType' object has no attribute 'update'
Odisseo
  • 747
  • 1
  • 13
  • 32

1 Answers1

0

Seaborn countplot is not unit aware. It would plot bars at numeric positions 0,1,2,..,N-1. Hence you cannot set the ticks to non-numeric positions. You can however change the ticklabels at those positions.

ax.set(xticks=range(len(jobs)), xticklabels=[i[0] for i in jobs])
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712