Seaborn条形图将yaxis设置为整数刻度

2024-09-30 22:12:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个水平seaborn条形图,y轴为整数刻度。当我尝试它时,我得到以下错误TypeError: unsupported operand type(s) for /: 'str' and 'int'。整数在列表y=['100', '200']中被引用,因此我认为它们将被解释为字符串。如果我在整数上加上一个或多个字母,效果很好,但不是我想要的标签。如何使用整数列表作为y轴刻度并避免此错误

不起作用吗

f, ax = plt.subplots(figsize=(6, 2))

sns.barplot(y=['100', '200'], x=[100, 75],
            color="#e9ffe1", orient='h')

plt.tight_layout()
plt.show()

有效:

f, ax = plt.subplots(figsize=(6, 2))

sns.barplot(y=['100s', '200s'], x=[100, 75],
            color="#e9ffe1", orient='h')

plt.tight_layout()
plt.show()

enter image description here

所需输出:

enter image description here


Tags: 列表错误plt整数axcolorlayoutsns