Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

First of all, I am using Python '2.7.3 | 64-bit, pandas 0.12.0, and numpy 1.8.0. I am following this tutorial on Pandas time series, however when I get to this:

filled.ix['2011-11-03':'2011-11-04'].between_time('09:30', '16:00').plot()
plt.figsize(10,8)
plt.ylim(103.5, 104.5)

I get this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-151-78e7fd271d16> in <module>()
----> 1 filled.ix['2011-11-03':'2011-11-04'].between_time('09:30', '16:00').plot()
      2 plt.figsize(10,8)
      3 plt.ylim(103.5, 104.5)

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/tools/plotting.pyc in plot_frame(frame, x, y, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, style, title, xlim, ylim, logx, logy, xticks, yticks, kind, sort_columns, fontsize, secondary_y, **kwds)
   1634                      logy=logy, sort_columns=sort_columns,
   1635                      secondary_y=secondary_y, **kwds)
-> 1636     plot_obj.generate()
   1637     plot_obj.draw()
   1638     if subplots:

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/tools/plotting.pyc in generate(self)
    854         self._compute_plot_data()
    855         self._setup_subplots()
--> 856         self._make_plot()
    857         self._post_plot_logic()
    858         self._adorn_subplots()

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _make_plot(self)
   1238         if not self.x_compat and self.use_index and self._use_dynamic_x():
   1239             data = self._maybe_convert_index(self.data)
-> 1240             self._make_ts_plot(data, **self.kwds)
   1241         else:
   1242             lines = []

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _make_ts_plot(self, data, **kwargs)
   1319                 self._maybe_add_color(colors, kwds, style, i)
   1320 
-> 1321                 _plot(data[col], i, ax, label, style, **kwds)
   1322 
   1323         self._make_legend(lines, labels)

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(data, col_num, ax, label, style, **kwds)
   1293         def _plot(data, col_num, ax, label, style, **kwds):
   1294             newlines = tsplot(data, plotf, ax=ax, label=label,
-> 1295                                 style=style, **kwds)
   1296             ax.grid(self.grid)
   1297             lines.append(newlines[0])

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/tseries/plotting.py in tsplot(series, plotf, **kwargs)
     75         args.append(style)
     76 
---> 77     lines = plotf(ax, *args, **kwargs)
     78     label = kwargs.get('label', None)
     79 

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axes.pyc in plot(self, *args, **kwargs)
   4135         lines = []
   4136 
-> 4137         for line in self._get_lines(*args, **kwargs):
   4138             self.add_line(line)
   4139             lines.append(line)

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axes.pyc in _grab_next_args(self, *args, **kwargs)
    315                 return
    316             if len(remaining) <= 3:
--> 317                 for seg in self._plot_args(remaining, kwargs):
    318                     yield seg
    319                 return

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axes.pyc in _plot_args(self, tup, kwargs)
    293             x = np.arange(y.shape[0], dtype=float)
    294 
--> 295         x, y = self._xy_from_xy(x, y)
    296 
    297         if self.command == 'plot':

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axes.pyc in _xy_from_xy(self, x, y)
    212         if self.axes.xaxis is not None and self.axes.yaxis is not None:
    213             bx = self.axes.xaxis.update_units(x)
--> 214             by = self.axes.yaxis.update_units(y)
    215 
    216             if self.command != 'plot':

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axis.pyc in update_units(self, data)
   1334         """
   1335 
-> 1336         converter = munits.registry.get_converter(data)
   1337         if converter is None:
   1338             return False

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/units.pyc in get_converter(self, x)
    135 
    136         if isinstance(x, np.ndarray) and x.size:
--> 137             xravel = x.ravel()
    138             try:
    139                 # pass the first value of x that is not masked back to

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/ma/core.pyc in ravel(self)
   4023         r._update_from(self)
   4024         if self._mask is not nomask:
-> 4025             r._mask = ndarray.ravel(self._mask).reshape(r.shape)
   4026         else:
   4027             r._mask = nomask

/home/luis/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/core/series.pyc in reshape(self, newshape, order)
    979             return self.values.reshape(newshape, order=order)
    980         else:
--> 981             return ndarray.reshape(self, newshape, order)
    982 
    983     def get(self, label, default=None):

TypeError: an integer is required

<matplotlib.figure.Figure at 0x5008050>

Maybe downgrading to a lower matplotlib or numpy version is the solution? I don't have any idea how to solve this problem.

share|improve this question
1  
what is the output of filled.ix['2011-11-03':'2011-11-04'].between_time('09:30', '16:00')? – behzad.nouri Dec 28 '13 at 20:03
1  
<class 'pandas.core.frame.DataFrame'> DatetimeIndex: 391 entries, 2011-11-03 09:30:00 to 2011-11-03 16:00:00 Freq: T Data columns (total 4 columns): open 380 non-null values high 380 non-null values low 380 non-null values close 380 non-null values dtypes: float64(4) – Luis Miguel Dec 28 '13 at 20:38
3  
IIRC this is a compat issue with matplotlib 1.3 and pandas 0.12. you can downgrade to 1.2 to fix. 0.13 (releasing very shortly) also resolves this – Jeff Dec 28 '13 at 22:00
    
Thank you Jeff. Will wait for 0.13 – Luis Miguel Dec 28 '13 at 22:41
    
@Jeff Do you have a reference on this? – tcaswell Jan 20 '14 at 3:21

Jeff knows the origins of this problem and says in the comments that it's a compatibility issue. My workaround until Anaconda is updated to resolve the problem has been to use dropna() in my plotting function calls. I don't know why it works but so far it has done in all cases! Since you probably don't care much about the NaNs it also has very little cost and you probably won't need to rewrite the code when the issue is resolved. eg.

filled.ix['2011-11-03':'2011-11-04'].between_time('09:30', '16:00').dropna().plot()
plt.figsize(10,8)
plt.ylim(103.5, 104.5)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.