无法在python pandas中获得未堆积的条形图 [英] Can't get un-stacked bar plot in python pandas

查看:51
本文介绍了无法在python pandas中获得未堆积的条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪.我只是似乎无法在python pandas中获得未堆积的条形图(与pandas官方指南不同).这些条似乎只是重叠,而不是横向放置.任何线索,为什么会这样?

This is weird. I just can't seem to get unstacked bar plot in python pandas (unlike pandas official guide). The bars just seem to be overlapped, instead of placed sideways. Any clue why it would be?

df.plot(kind='bar',stacked=False, figsize=(20,15), alpha=0.4)

这是图像的链接:

这是样本df

                OLS     Ridge     Lasso        EN
BN         0.008935  0.013937  0.000000  0.000000
BO         0.037947  0.034341  0.021778  0.021771
BP         0.205764  0.190278  0.184766  0.179000
CB         0.302772  0.106399  0.161487  0.076948
CD         0.464572  0.378660  0.424983  0.401792
CF         0.062425  0.006078  0.000000 -0.000000
CL        -0.005794  0.002631  0.000000  0.001082
CN         0.012761  0.011331  0.010272  0.010476

推荐答案

好.因此,现在我必须问一下您使用的是哪个版本的熊猫.当我跑步时:

Ok. So now I have to ask what version of pandas you're on. When I run:

from matplotlib import pyplot as plt
import pandas
try:
    from io import StringIO
except:
    from StringIO import StringIO

data = StringIO("""\
                OLS     Ridge     Lasso        EN
BN         0.008935  0.013937  0.000000  0.000000
BO         0.037947  0.034341  0.021778  0.021771
BP         0.205764  0.190278  0.184766  0.179000
CB         0.302772  0.106399  0.161487  0.076948
CD         0.464572  0.378660  0.424983  0.401792
CF         0.062425  0.006078  0.000000 -0.000000
CL        -0.005794  0.002631  0.000000  0.001082
CN         0.012761  0.011331  0.010272  0.010476
""")

df = pandas.read_csv(data, sep='\s+')
fig, axes = plt.subplots(nrows=2, figsize=(6, 10))
df.plot(kind='bar', stacked=False, alpha=0.4, ax=axes[0])
df.plot(kind='bar', stacked=True, alpha=0.4, ax=axes[1])
for ax in axes:
    ax.set_ylim(bottom=0)

我得到:

我通过(ana)conda进入大熊猫0.13

I'm on pandas 0.13 via (ana)conda

这篇关于无法在python pandas中获得未堆积的条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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