绘制pandas中的子图时的IndexError

时间:2015-02-10 21:37:53

标签: python pandas

我的数据框如下:

(使用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}})

根据列出的文档here,您应该可以这样做:

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

但是,结果是:IndexError: too many indices for array

绘制子图的最简单方法是什么?

1 个答案:

答案 0 :(得分:6)

我将从这里的评论中复制汤姆的答案。

  

检查axes.shape。它是(2,),因此您只需要.plot(ax=axes[0])。   subplots=True

还有DataFrame.plot个参数

它应该有用。