Skip to content

Instantly share code, notes, and snippets.

@sinhrks
Created March 23, 2014 04:57
Show Gist options
  • Save sinhrks/9719021 to your computer and use it in GitHub Desktop.
Save sinhrks/9719021 to your computer and use it in GitHub Desktop.
Pandas dataframe with centered bar
import string
from pandas import DataFrame, Series
from numpy.random import randn
import matplotlib.pyplot as plt
df = DataFrame(randn(7, 4),
index=list(string.ascii_letters[:7]),
columns=['x', 'y', 'z', 'four'])
series = Series(randn(7), index=range(7))
fig, axes = plt.subplots(1, 4, figsize=(14, 3))
plt.subplots_adjust(top=0.9, bottom=0.1, left=0.05, right=0.95, hspace=0.35)
df.plot(kind='bar', title='Default(center)', ax=axes[0], legend=False)
series.plot(ax=axes[0])
df.plot(kind='bar', stacked=True, title='Default(center)', ax=axes[1], legend=False)
series.plot(ax=axes[1])
df.plot(kind='bar', title='Align=edge', ax=axes[2], legend=False, align='edge')
series.plot(ax=axes[2])
df.plot(kind='bar', stacked=True, title='Align=edge', ax=axes[3], legend=False, align='edge')
series.plot(ax=axes[3])
plt.show()
@sinhrks
Copy link
Author

sinhrks commented Mar 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment