3

I have a dataframe that looks like:

(Using ipython notebook..)

import pandas as pd
pd.options.display.mpl_style = 'default'
%matplotlib
import matplotlib.pyplot as plt

df = pd.DataFrame({'Average': {'April- 2014': 94.400000000000006,
  'August- 2014': 94.400000000000006,
  'December- 2014': 94.400000000000006,
  'February- 2015': 94.400000000000006,
  'January- 2015': 94.400000000000006,
  'July- 2014': 94.400000000000006,
  'June- 2014': 94.400000000000006,
  'May- 2014': 94.400000000000006,
  'November- 2014': 94.400000000000006,
  'October- 2014': 94.400000000000006,
  'September- 2014': 94.400000000000006},
 'Number': {'April- 2014': 80,
  'August- 2014': 86,
  'December- 2014': 110,
  'February- 2015': 11,
  'January- 2015': 104,
  'July- 2014': 90,
  'June- 2014': 83,
  'May- 2014': 108,
  'November- 2014': 118,
  'October- 2014': 127,
  'September- 2014': 107}})

Per the documentation listed here you should be able to do this:

fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(15, 8))
df['Number'].plot(ax=axes[0, 0])

However, it results in: IndexError: too many indices for array

What's the easiest way to plot subplots?

3
  • 3
    Check your axes.shape. It's (2,) so you only need .plot(ax=axes[0]). There's also the subplots=True argument to DataFrame.plot Commented Feb 10, 2015 at 22:01
  • 1
    Ah, interesting. Not very intuitive. That solved it though. Thanks! Commented Feb 10, 2015 at 22:55
  • 1
    @TomAugspurger You should post it as an answer so this post doesn't remain unanswered Commented Feb 11, 2015 at 9:36

1 Answer 1

6

I will copy Tom's answer from the comments here.

Check your axes.shape. It's (2,) so you only need .plot(ax=axes[0]). There's also the subplots=True argument to DataFrame.plot

It should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.