如何从seaborn / matplotlib图中删除或隐藏x轴标签?

LaLaTi

我有一个箱线图,需要删除x轴(“ user_type”和“ member_gender”)标签。给定以下格式,我该如何做?

sb.boxplot(x="user_type", y="Seconds", data=df, color = default_color, ax = ax[0,0], sym='').set_title('User-Type (0=Non-Subscriber, 1=Subscriber)')
sb.boxplot(x="member_gender", y="Seconds", data=df, color = default_color, ax = ax[1,0], sym='').set_title('Gender (0=Male, 1=Female, 2=Other)')
特伦顿·麦金尼
  • 创建箱线图后,使用.set()
  • .set(xticklabels=[]) 应该删除刻度线标签。
    • 如果使用.set_title()则无法使用,但可以使用.set(title='')
  • .set(xlabel=None) 应去除轴标签。
  • .tick_params(bottom=False) 将删除刻度线。
  • 同样,对于y轴:如何从matplotlib / seaborn图中删除或隐藏y轴刻度标签?
fig, ax = plt.subplots(2, 1)

g1 = sb.boxplot(x="user_type", y="Seconds", data=df, color = default_color, ax = ax[0], sym='')
g1.set(xticklabels=[])
g1.set(title='User-Type (0=Non-Subscriber, 1=Subscriber)')
g1.set(xlabel=None)

g2 = sb.boxplot(x="member_gender", y="Seconds", data=df, color = default_color, ax = ax[1], sym='')
g2.set(xticklabels=[])
g2.set(title='Gender (0=Male, 1=Female, 2=Other)')
g2.set(xlabel=None)

带xticks和xlabel

import seaborn as sns
import matplotlib.pyplot as plt

# load data
exercise = sns.load_dataset('exercise')
pen = sns.load_dataset('penguins')

# create figures
fig, ax = plt.subplots(2, 1, figsize=(8, 8))

# plot data
g1 = sns.boxplot(x='time', y='pulse', hue='kind', data=exercise, ax=ax[0])

g2 = sns.boxplot(x='species', y='body_mass_g', hue='sex', data=pen, ax=ax[1])

plt.show()

在此处输入图片说明

没有xticks和xlabel

fig, ax = plt.subplots(2, 1, figsize=(8, 8))

g1 = sns.boxplot(x='time', y='pulse', hue='kind', data=exercise, ax=ax[0])

g1.set(xticklabels=[])  # remove the tick labels
g1.set(title='Exercise: Pulse by Time for Exercise Type')  # add a title
g1.set(xlabel=None)  # remove the axis label

g2 = sns.boxplot(x='species', y='body_mass_g', hue='sex', data=pen, ax=ax[1])

g2.set(xticklabels=[])  
g2.set(title='Penguins: Body Mass by Species for Gender')
g2.set(xlabel=None)
g2.tick_params(bottom=False)  # remove the ticks

plt.show()

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在散景图中旋转X轴标签?

matplotlib:如何防止x轴标签彼此重叠

matplotlib:如何防止x轴标签彼此重叠

如何在chart.js的条形图中隐藏y轴和x轴线以及标签

如何在matplotlib / seaborn上使用LaTex符号设置轴标签的字体大小?

如何删除簇图中的x和y轴标签?

Seaborn如何处理长轴标签?

如何使用matplotlib和seaborn在绘制的值上显示轴刻度标签?

如何在海图中设置x轴刻度标签?

如何在seaborn中替代x标签?

如何更改海洋线图中的x轴标签的顺序?

如何在Seaborn Facetgrid中删除重复的轴标签?

如何旋转Seaborn Barplot X轴刻度标签?

如何在Seaborn的对图中绘制右轴和上轴并删除左轴和底轴?

如何单独隐藏/删除轴而不删除全息视图中的轴标签

如何在每5个刻度之间隐藏x轴标签,以便使图表在matplotlib中看起来更干净?

Seaborn图中x轴标签的间距

如何在seaborn图中显示交集标签?

如何在Matplotlib和Seaborn中的x轴刻度线(不是刻度线标签)和x轴之间添加填充

(Matplotlib) 如何在复杂条形图中删除刻度并将标签添加到多个图层(具有多个断轴)

如何删除matplotlib折线图中的轴刻度?

如何使用 ax.tick_params 隐藏 x 轴标签?

如何使用子图在 Seaborn 散点图中旋转 x 轴刻度标签

如何使用 Plotly 删除堆叠和分组条形图中的 x 轴刻度标签

如何从子图中的一个轴上删除标签?

如何更改折线图上的 x 轴标签 - Seaborn

如何在python条形图中添加x轴标签

在 Seaborn Matplotlib PyQT5 中调整 x 轴和 y 轴标签的字体大小

如何在 matplotlib 3d 图中删除轴值