如何轻松地将 Pandas 条形图转换为水平图? [英] How can I easily convert a Pandas barplot to horizontal?

查看:85
本文介绍了如何轻松地将 Pandas 条形图转换为水平图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用水平条绘制条形图.有什么办法可以调整下面的脚本吗?

I'm trying to plot a barplot with horizontal bars. Is there any way I could do this adapting the script below?

ax = fig.add_subplot(121)
ax = df['colum_1'].plot(kind='bar',
                                figsize=(14,8),
                                title="Column1");

我知道有 barh 函数,但我想知道上面的代码是否有任何修改可以做到这一点.

I know that there is the barh function, but I was wondering if there is any adaptation from the code above to do that.

推荐答案

将 kind 从 ‘bar’ 改为 ‘barh’

Change kind from ‘bar’ to ‘barh’

ax = fig.add_subplot(121)
ax = df['colum_1'].plot(kind='barh', figsize=(14), title="Column1");

更新

确保它们不重叠.使用以下方法:

To make sure that they don't overlap. Use the following approach:

fig, axs = plt.subplots(1,2)
axs[0] = df['colum_1'].plot(kind='bar', figsize=(14), title="Column1")
axs[1] = df['colum_1'].plot(kind='barh', figsize=(14), title="Column1")

这篇关于如何轻松地将 Pandas 条形图转换为水平图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆