Seaborn条形图-将y轴设置为整数刻度

时间:2020-02-08 18:50:08

标签: python matplotlib bar-chart seaborn

我正在尝试创建一个水平的Seabar条形图,其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

1 个答案:

答案 0 :(得分:0)

已升级到Seaborn 0.10以解决问题。

pip install seaborn --upgrade