Python 3.x 如何从seaborn/matplotlib绘图中删除或隐藏x轴标签
我有一个箱线图,需要删除x轴(“用户类型”和“成员性别”)标签。鉴于以下格式,我如何做到这一点Python 3.x 如何从seaborn/matplotlib绘图中删除或隐藏x轴标签,python-3.x,pandas,matplotlib,seaborn,Python 3.x,Pandas,Matplotlib,Seaborn,我有一个箱线图,需要删除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, c
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.tick_参数(bottom=False)
- 类似地,对于y轴:
fig,ax=plt.子批次(2,1)
g1=sb.箱线图(x=“用户类型”,y=“秒”,数据=df,颜色=default\u颜色,ax=ax[0],符号=”)
g1.set(xticklabels=[])
g1.set(title='User-Type(0=非订户,1=订户)')
g1.set(xlabel=None)
g2=sb.箱线图(x=“成员性别”,y=“秒”,数据=df,颜色=default\u颜色,ax=ax[1],符号=”)
g2.set(xticklabels=[])
g2.set(title='Gender(0=男性,1=女性,2=其他)')
g2.set(xlabel=None)
例子
使用xticks和xlabel
导入seaborn作为sns
将matplotlib.pyplot作为plt导入
#加载数据
exercise=sns.load\u数据集(“exercise”)
pen=sns.load\u数据集('penguins')
#创造数字
图,ax=plt.子批次(2,1,figsize=(8,8))
#绘图数据
g1=sns.boxplot(x='time',y='pulse',hue='kind',data=exercise,ax=ax[0])
g2=sns.boxplot(x='classes',y='body\u mass\u g',hue='sex',data=pen,ax=ax[1])
plt.show()
没有xticks和xlabel
fig,ax=plt.子批次(2,1,figsize=(8,8))
g1=sns.boxplot(x='time',y='pulse',hue='kind',data=exercise,ax=ax[0])
g1.设置(xticklabels=[])#删除勾号标签
g1.设置(title='Exercise:Pulse by Time for Exercise Type')#添加一个标题
g1.设置(xlabel=None)#移除轴标签
g2=sns.boxplot(x='classes',y='body\u mass\u g',hue='sex',data=pen,ax=ax[1])
g2.set(xticklabels=[])
g2.集合(标题为“企鹅:性别按物种划分的体重”)
g2.set(xlabel=None)
g2.勾选参数(底部=假)#删除勾选
plt.show()
特伦顿,谢谢@不客气