You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Seaborn计数图的x轴标签、y轴标签及y轴刻度值?

移除Seaborn计数图的轴标签与y轴刻度值

你可以通过操作Seaborn返回的Axes对象,结合Matplotlib的API来移除这些元素,具体代码如下:

import seaborn as sns
import matplotlib.pyplot as plt

# 绘制计数图
g = sns.countplot(x='Vertical', data=Report)

# 移除x轴标签
g.set_xlabel('')
# 移除y轴标签
g.set_ylabel('')
# 移除y轴的刻度值
g.set_yticks([])

# 展示图形
plt.show()

各步骤说明:

  • g.set_xlabel(''):将x轴标签设置为空字符串,隐藏原有的"Vertical"标签
  • g.set_ylabel(''):同理,隐藏y轴的"count"标签
  • g.set_yticks([]):传入空列表,清除y轴上的所有刻度值

如果偏好更简洁的链式写法,也可以这样写:

g = sns.countplot(x='Vertical', data=Report)
g.set(xlabel='', ylabel='').set_yticks([])
plt.show()

内容的提问来源于stack exchange,提问作者Venkat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 16:30:40