11

This is what I have right now:

np.random.seed(1234)
test = pd.DataFrame({'week': [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2],
                     'score': np.random.uniform(0, 1, 12),
                     'type': [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
                     'type2': [3, 3, 4, 4, 5, 5, 3, 3, 4, 4, 5, 5]})

test.groupby(['week', 'type', 'type2']).agg('sum').unstack().plot(kind='bar')

enter image description here

How do I plot facet based on 'type'? I want two different plots, one for type = 1 and another type = 2.

Max Ghenis
  • 14,783
  • 16
  • 84
  • 132
collarblind
  • 4,549
  • 13
  • 31
  • 49
  • You might take a look at seaborn (based on pandas and matplotlib) http://stanford.edu/~mwaskom/software/seaborn/tutorial/axis_grids.html – JohnE Apr 22 '15 at 02:16

1 Answers1

15

You need to unstack so type are columns, and then use the subplots parameter:

test.groupby(['week', 'type', 
              'type2']).agg('sum').unstack(1).plot(kind='bar', subplots=True)

Resulting plot

Max Ghenis
  • 14,783
  • 16
  • 84
  • 132
JAB
  • 12,401
  • 6
  • 45
  • 50