Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

First of all, I am using '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 about 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 2 days ago
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 2 days ago
1  
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 2 days ago
 
Thank you Jeff. Will wait for 0.13 –  Luis Miguel 2 days ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.