我有一个方框图,需要删除x轴("用户类型"和"成员性别")标签.鉴于以下格式,我该怎么做?

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

推荐答案

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()

enter image description here

没有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()

enter image description here

Python-3.x相关问答推荐

错误2没有这样的文件或目录website_content.txt""

为什么我必须在绘制椭圆时代码等于两次?''

Numpy将3D数组的每个切片相乘以进行转置并对其求和

我想判断df_entry_log[AM_PM],并根据测试填充列

当索引大于一个整数而小于前一个索引时,我如何返回列值?

从.csv导入将文件夹路径加入到文件名

使用数据库将文件从Sharepoint下载到文件系统

将两列的乘积连续添加到一列的累积和中

CSV-DAT 转换时将引号添加到数据中

如何使用 Selenium Python 连续单击一个按钮直到另一个元素出现?

如何将函数映射到所有命名元组的元素?

如何根据索引子列表对元素列表进行分组或批处理?

如何在 Telethon 中向机器人发送发送表情符号

!date 的命令无法从 jupyter notebook 运行

无法使用 Python 和 Selenium 检索 href 属性

Python:如何在三个列表中找到共同值

Python3四舍五入到最接近的偶数

asyncio.Semaphore RuntimeError: Task got Future 附加到不同的循环

如何找出从哪个模块导入名称?

将字符串拆分为最大长度 X 的片段 - 仅在空格处拆分