繁体   English   中英

在 Regplot Seaborn 中更改 x 刻度

[英]Change x ticks in Regplot Seaborn

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

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

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

在此处输入图像描述

我设法找到了这个解决方案:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM