如何从 Seaborn/Matplotlib 绘图中删除或隐藏 X 轴标签?


要从 SeabornMatplotlib 绘图 中删除或隐藏 X 轴标签,我们可以采取以下步骤 −

  • 设置图形大小并调整子图之间和周围的填充。

  • 使用sns.set_style() 为 Seaborn 绘图设置美学样式。

  • 从在线存储库中加载示例数据集(需要互联网)。

  • 要隐藏或删除 X 轴标签,请使用set(xlabel=None)

  • 要显示图形,请使用show() 方法。

示例

from matplotlib import pyplot as plt
import seaborn as sns

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

sns.set_style("whitegrid")
tips = sns.load_dataset("tips")

ax = sns.boxplot(x="day", y="total_bill", data=tips)
ax.set(xlabel=None)

plt.show()

输出

更新于:12-09-2023

38K+ 浏览

开启你的 职业生涯

完成课程取得认证

开始
广告
© . All rights reserved.