更改Regplot Seaborn中的x刻度

时间:2020-04-24 14:33:08

标签: python python-3.x plot seaborn

是否可以使用seaborn更改regplot中x刻度的“名称”?

我有一个包含分类变量的数据集(dataset),我正在尝试对此进行线性回归:

import seaborn as sns
fig  = sns.regplot(x='Cond_L', y='RT', data=dataset, x_estimator=np.mean)

Cond_L似乎是一个数字变量,但它是具有以下可能值的绝对变量:1234

但是,绘制时,我的x轴从1变到4,但以0.5为步幅,而不是1。

所以我的问题是(1)如何只有四个刻度线; (2)如何将数字更改为文本,即Cond1Cond2Cond3Cond4

enter image description here

1 个答案:

答案 0 :(得分:0)

我设法找到了解决方案:

ax.set(xticks=np.arange(1, 5, 1))  #limit the number of ticks to 4
ax.set_xticklabels(['Cond1','Cond2','Cond3', "Cond4"]) #rename ticks