【问题标题】:Set Ticks in Seaborn Countplot在 Seaborn Countplot 中设置刻度
【发布时间】:2019-01-13 09:13:15
【问题描述】:

我已使用以下代码在 seaborn 中设置 xticks,但这不起作用。我的 xticks 标签来自一个列表,并且它们已经正确排序。

[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'

【问题讨论】:

    标签: python-3.x matplotlib seaborn figure aesthetics


    【解决方案1】:

    Seaborn countplot 不知道单位。它将在数字位置 0,1,2,..,N-1 处绘制条形图。因此,您不能将刻度设置为非数字位置。但是,您可以更改这些位置的刻度标签。

    ax.set(xticks=range(len(jobs)), xticklabels=[i[0] for i in jobs])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 1970-01-01
      • 2021-04-08
      • 1970-01-01
      相关资源
      最近更新 更多