jxn
jxn

Reputation: 8025

Python: How to overlay 2 bar plots from pandas plot

I want to superimpose 2 bar plots with same x-xis. I have a dataframe with this data:

df = pd.DataFrame({'a':[1,2,3,1,2,2,2],
             'b':[1,1,1,3,2,2,2]})

I can plot 2 histogram plots for a and b:

df['a'].value_counts().plot(kind = 'bar')
df['b'].value_counts().plot(kind = 'bar')

enter image description here enter image description here

How can i superimpose one of them on the other ?

Example of an unrelated chart format that im looking for: enter image description here

Upvotes: 2

Views: 3126

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

Use width and ax paramters:

ax = df['a'].value_counts().plot(kind='bar', color='blue', width=.75, legend=True, alpha=0.8)
df['b'].value_counts().plot(kind='bar', color='maroon', width=.5, alpha=1, legend=True)

Output:

enter image description here

Upvotes: 2

Related Questions