Skip to content Skip to sidebar Skip to footer

Can't Get Un-stacked Bar Plot In Python 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 clu

Solution 1:

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)

I get: enter image description here

I'm on pandas 0.13 via (ana)conda

Post a Comment for "Can't Get Un-stacked Bar Plot In Python Pandas"