当 Catplot 图是子图的一部分时,如何修改它的 "ylabel" 属性?

How Do I Modify the "ylabel" Property of a Catplot Graph When it is Part of a Subplot?

我正在尝试修改子图中 2 个 seaborn 图的 ylabel 属性。但是,在每个轴上使用 set_ylabel() 函数什么都不做。

我不能直接使用 FacetGrid 因为某些原因它不适用于子图(它绘制额外的空网格,这就是为什么我在每个之后调用 close()平局)。

import matplotlib.pyplot as plt 
import seaborn as sns

fig_a, ax_a = plt.subplots(1, 2, figsize = (16, 8))

fig_a.suptitle("Frequency of Exercise by Age")

ax_a[0].set_ylim([0, 500])
ax_a[0].set(ylabel = "Ylabel Test 1")
ax_a[0].set_title("Males (" + str(len(male_age_data)) + "/" + str(len(age_data)) + ")")

ax_a[1].set_ylim([0, 500])
ax_a[1].set_ylabel("Ylabel Test 2")
ax_a[1].set_title("Females (" + str(len(female_age_data)) + "/" + str(len(age_data)) + ")")

sns.catplot(x = "Active", hue = "Age", data = male_age_data, kind = "count", order = ["Inactive", "Active", "Very Active"], hue_order = ["<= 20", "21-30", "31-40", "41-50", "51-60", "61-70", "71-80"], ax = ax_a[0])

plt.close()

sns.catplot(x = "Active", hue = "Age", data = female_age_data, kind = "count", order = ["Inactive", "Active", "Very Active"], hue_order = ["<= 20", "21-30", "31-40", "41-50", "51-60", "61-70", "71-80"], ax = ax_a[1])

plt.close()

Here is the output,如您所见,y-label 仍然是默认的 "count"。

在轴上设置标题效果很好,我很好奇为什么它不影响 y-label 以及如何解决这个问题?

catplot 似乎覆盖了 ylabel。尝试在 catplot 命令之后移动 ylabel 命令。

我能够重现您的问题并通过这种方式更改命令的顺序来修复它。