首页 > 解决方案 > 在 Pandas plot() 中指定 y_label

问题描述

我想在下面的 Pandas 绘图函数中指定 y_label,但似乎语法不正确。

row = df.iloc[0].astype(int)
row.value_counts().reindex().plot(ylabel='something').bar()

因为错误是

bar() missing 2 required positional arguments: 'x' and 'height'

如果我使用row.value_counts().reindex().plot().bar(),没有问题,但也没有 y_label 。我该如何解决?

标签: pandasplot

解决方案


这应该有效:

ax = row.value_counts().reindex().plot(kind='bar')
ax.set_ylabel("something")

推荐阅读