xlabels 不会在 python 中以 seaborn 和 tight despined 布局出现

xlabels do not show up with seaborn and tight despined layout in python

我想用旋转的 xtick 标签绘制以下数据框,同时还具有紧凑的 despined 布局(使用来自 matplotlib 的 tight_layout() 和来自 seaborn 的 despine)。以下内容不起作用,因为标签未显示:

import matplotlib.pylab as plt
import seaborn as sns
import pandas
df = pandas.DataFrame({"x": ["XYZ1", "XYZ2", "XYZ3", "XYZ4"],
                       "y": [0, 1, 0, 1]})
plt.figure(figsize=(5,5))
sns.set_style("ticks")
g = sns.pointplot(x="x", y="y", data=df)
sns.despine(trim=True, offset=2)
g.set_xticklabels(g.get_xticklabels(), rotation=55, ha="center")
plt.tight_layout()

它产生:

xtick 标签("XYZ1"、"XYZ2"、...)不会出现。如果我删除 despine,则会出现滴答声,但不会出现 despined。如果我在 despine/tight_layout 之前更改刻度,它们会出现但不会旋转。如何才能做到这一点?

在我的机器上以下工作

import matplotlib.pylab as plt
import seaborn as sns
import pandas
df = pandas.DataFrame({"x": ["XYZ1", "XYZ2", "XYZ3", "XYZ4"],
                       "y": [0, 1, 0, 1]})
plt.figure(figsize=(5,5))
sns.set_style("ticks")
g = sns.pointplot(x="x", y="y", data=df)
sns.despine(trim=True, offset=2)
g.set_xticklabels(df['x'], rotation=55, ha="center")
plt.tight_layout()
plt.show()

并生产