Plotting with Gridspec: Index Beyond the Boundary
I used to use a lot of gridspec, but today I have a bug that I never used. Here is some sample code taken from the pandas build example page:
import pandas as pd from pandas import * import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000)) ts = ts.cumsum() df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD')) df = df.cumsum() df3 = pd.DataFrame(np.random.randn(1000, 2), columns=['B', 'C']).cumsum() df3['A'] = pd.Series(list(range(len(df)))) gs = gridspec.GridSpec(5,1) fig = plt.figure(figsize=(6, 6), facecolor='white') ax = fig.add_subplot(gs[:4, :]) ax2 = fig.add_subplot(gs[4, :]) df3.plot(x='A', y='B', ax=ax2)
While it looks correct, I have an error that stops the program:
---> 21 df3.plot (x = 'A', y = 'B', ax = ax2)
IndexError: index 4 is out of bounds for axis 0 with size 3
Note: The index 4
error message is directly related to the gridspec limits. If I remove the gridspec the plot works well.
Pandas version: 0.16.1
Matplotlib version: 1.4.3
+3
source to share
No one has answered this question yet
Check out similar questions: