Memory Error when plotting time series in pandas dataframe

Viewed 833

I'm running Pandas 0.17.1 & Python 2.7.11 and I've got a pandas dataframe, shown below, with 3311 rows and 7 columns. It's fairly sparse as each column represents a sensor sampling at a diffferent rate (anywhere from 1Hz to 32Hz)

dataframe

When I go to plot it using df.plot() I get a long callback (below) with a few MemoryErrors sprinkled in.


MemoryError                               Traceback (most recent call last)
<ipython-input-17-4f76bcc16520> in <module>()
----> 1 df.plot()

C:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   3669                           fontsize=fontsize, colormap=colormap, table=table,
   3670                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671                           sort_columns=sort_columns, **kwds)
   3672     __call__.__doc__ = plot_frame.__doc__
   3673 

C:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   2554                  yerr=yerr, xerr=xerr,
   2555                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556                  **kwds)
   2557 
   2558 

C:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
   2382         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   2383 
-> 2384     plot_obj.generate()
   2385     plot_obj.draw()
   2386     return plot_obj.result

C:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in generate(self)
    991 
    992         for ax in self.axes:
--> 993             self._post_plot_logic_common(ax, self.data)
    994             self._post_plot_logic(ax, self.data)
    995 

C:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _post_plot_logic_common(self, ax, data)
   1119                 ax.set_xticklabels(xticklabels)
   1120             self._apply_axis_properties(ax.xaxis, rot=self.rot,
-> 1121                                         fontsize=self.fontsize)
   1122             self._apply_axis_properties(ax.yaxis, fontsize=self.fontsize)
   1123         elif self.orientation == 'horizontal':

C:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _apply_axis_properties(self, axis, rot, fontsize)
   1167 
   1168     def _apply_axis_properties(self, axis, rot=None, fontsize=None):
-> 1169         labels = axis.get_majorticklabels() + axis.get_minorticklabels()
   1170         for label in labels:
   1171             if rot is not None:

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in get_majorticklabels(self)
   1159     def get_majorticklabels(self):
   1160         'Return a list of Text instances for the major ticklabels'
-> 1161         ticks = self.get_major_ticks()
   1162         labels1 = [tick.label1 for tick in ticks if tick.label1On]
   1163         labels2 = [tick.label2 for tick in ticks if tick.label2On]

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in get_major_ticks(self, numticks)
   1288         'get the tick instances; grow as necessary'
   1289         if numticks is None:
-> 1290             numticks = len(self.get_major_locator()())
   1291         if len(self.majorTicks) < numticks:
   1292             # update the new tick label properties from the old

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in __call__(self)
    901             vmin, vmax = vmax, vmin
    902         if self.isdynamic:
--> 903             locs = self._get_default_locs(vmin, vmax)
    904         else:  # pragma: no cover
    905             base = self.base

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in _get_default_locs(self, vmin, vmax)
    882 
    883         if self.plot_obj.date_axis_info is None:
--> 884             self.plot_obj.date_axis_info = self.finder(vmin, vmax, self.freq)
    885 
    886         locator = self.plot_obj.date_axis_info

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in _daily_finder(vmin, vmax, freq)
    505                     Period(ordinal=int(vmax), freq=freq))
    506     span = vmax.ordinal - vmin.ordinal + 1
--> 507     dates_ = PeriodIndex(start=vmin, end=vmax, freq=freq)
    508     # Initialize the output
    509     info = np.zeros(span,

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in __new__(cls, data, ordinal, freq, start, end, periods, copy, name, tz, **kwargs)
    181             else:
    182                 data, freq = cls._generate_range(start, end, periods,
--> 183                                                  freq, kwargs)
    184         else:
    185             ordinal, freq = cls._from_arraylike(data, freq, tz)

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in _generate_range(cls, start, end, periods, freq, fields)
    195                 raise ValueError('Can either instantiate from fields '
    196                                  'or endpoints, but not both')
--> 197             subarr, freq = _get_ordinal_range(start, end, periods, freq)
    198         elif field_count > 0:
    199             subarr, freq = _range_from_fields(freq=freq, **fields)

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in _get_ordinal_range(start, end, periods, freq, mult)
    992                              dtype=np.int64)
    993     else:
--> 994         data = np.arange(start.ordinal, end.ordinal + 1, mult, dtype=np.int64)
    995 
    996     return data, freq

MemoryError: 

Error in callback <function post_execute at 0x000000000A2304A8> (for post_execute):
---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
C:\Anaconda2\lib\site-packages\matplotlib\pyplot.pyc in post_execute()
    145             def post_execute():
    146                 if matplotlib.is_interactive():
--> 147                     draw_all()
    148 
    149             # IPython >= 2

C:\Anaconda2\lib\site-packages\matplotlib\_pylab_helpers.pyc in draw_all(cls, force)
    148         for f_mgr in cls.get_all_fig_managers():
    149             if force or f_mgr.canvas.figure.stale:
--> 150                 f_mgr.canvas.draw_idle()
    151 
    152 atexit.register(Gcf.destroy_all)

C:\Anaconda2\lib\site-packages\matplotlib\backend_bases.pyc in draw_idle(self, *args, **kwargs)
   2024         if not self._is_idle_drawing:
   2025             with self._idle_draw_cntx():
-> 2026                 self.draw(*args, **kwargs)
   2027 
   2028     def draw_cursor(self, event):

C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_agg.pyc in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

C:\Anaconda2\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

C:\Anaconda2\lib\site-packages\matplotlib\figure.pyc in draw(self, renderer)
   1131         dsu.sort(key=itemgetter(0))
   1132         for zorder, a, func, args in dsu:
-> 1133             func(*args)
   1134 
   1135         renderer.close_group('figure')

C:\Anaconda2\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.pyc in draw(self, renderer, inframe)
   2302 
   2303         for zorder, a in dsu:
-> 2304             a.draw(renderer)
   2305 
   2306         renderer.close_group('axes')

C:\Anaconda2\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in draw(self, renderer, *args, **kwargs)
   1104         renderer.open_group(__name__)
   1105 
-> 1106         ticks_to_draw = self._update_ticks(renderer)
   1107         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
   1108                                                                 renderer)

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in _update_ticks(self, renderer)
    947 
    948         interval = self.get_view_interval()
--> 949         tick_tups = [t for t in self.iter_ticks()]
    950         if self._smart_bounds:
    951             # handle inverted limits

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in iter_ticks(self)
    890         Iterate through all of the major and minor ticks.
    891         """
--> 892         majorLocs = self.major.locator()
    893         majorTicks = self.get_major_ticks(len(majorLocs))
    894         self.major.formatter.set_locs(majorLocs)

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in __call__(self)
    901             vmin, vmax = vmax, vmin
    902         if self.isdynamic:
--> 903             locs = self._get_default_locs(vmin, vmax)
    904         else:  # pragma: no cover
    905             base = self.base

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in _get_default_locs(self, vmin, vmax)
    882 
    883         if self.plot_obj.date_axis_info is None:
--> 884             self.plot_obj.date_axis_info = self.finder(vmin, vmax, self.freq)
    885 
    886         locator = self.plot_obj.date_axis_info

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in _daily_finder(vmin, vmax, freq)
    505                     Period(ordinal=int(vmax), freq=freq))
    506     span = vmax.ordinal - vmin.ordinal + 1
--> 507     dates_ = PeriodIndex(start=vmin, end=vmax, freq=freq)
    508     # Initialize the output
    509     info = np.zeros(span,

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in __new__(cls, data, ordinal, freq, start, end, periods, copy, name, tz, **kwargs)
    181             else:
    182                 data, freq = cls._generate_range(start, end, periods,
--> 183                                                  freq, kwargs)
    184         else:
    185             ordinal, freq = cls._from_arraylike(data, freq, tz)

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in _generate_range(cls, start, end, periods, freq, fields)
    195                 raise ValueError('Can either instantiate from fields '
    196                                  'or endpoints, but not both')
--> 197             subarr, freq = _get_ordinal_range(start, end, periods, freq)
    198         elif field_count > 0:
    199             subarr, freq = _range_from_fields(freq=freq, **fields)

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in _get_ordinal_range(start, end, periods, freq, mult)
    992                              dtype=np.int64)
    993     else:
--> 994         data = np.arange(start.ordinal, end.ordinal + 1, mult, dtype=np.int64)
    995 
    996     return data, freq

MemoryError: 

---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
C:\Anaconda2\lib\site-packages\IPython\core\formatters.pyc in __call__(self, obj)
    335                 pass
    336             else:
--> 337                 return printer(obj)
    338             # Finally look for special method names
    339             method = _safe_get_formatter_method(obj, self.print_method)

C:\Anaconda2\lib\site-packages\IPython\core\pylabtools.pyc in <lambda>(fig)
    205 
    206     if 'png' in formats:
--> 207         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    208     if 'retina' in formats or 'png2x' in formats:
    209         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

C:\Anaconda2\lib\site-packages\IPython\core\pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
    115 
    116     bytes_io = BytesIO()
--> 117     fig.canvas.print_figure(bytes_io, **kw)
    118     data = bytes_io.getvalue()
    119     if fmt == 'svg':

C:\Anaconda2\lib\site-packages\matplotlib\backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2176                     orientation=orientation,
   2177                     dryrun=True,
-> 2178                     **kwargs)
   2179                 renderer = self.figure._cachedRenderer
   2180                 bbox_inches = self.figure.get_tightbbox(renderer)

C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    525 
    526     def print_png(self, filename_or_obj, *args, **kwargs):
--> 527         FigureCanvasAgg.draw(self)
    528         renderer = self.get_renderer()
    529         original_dpi = renderer.dpi

C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_agg.pyc in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

C:\Anaconda2\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

C:\Anaconda2\lib\site-packages\matplotlib\figure.pyc in draw(self, renderer)
   1131         dsu.sort(key=itemgetter(0))
   1132         for zorder, a, func, args in dsu:
-> 1133             func(*args)
   1134 
   1135         renderer.close_group('figure')

C:\Anaconda2\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.pyc in draw(self, renderer, inframe)
   2302 
   2303         for zorder, a in dsu:
-> 2304             a.draw(renderer)
   2305 
   2306         renderer.close_group('axes')

C:\Anaconda2\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in draw(self, renderer, *args, **kwargs)
   1104         renderer.open_group(__name__)
   1105 
-> 1106         ticks_to_draw = self._update_ticks(renderer)
   1107         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
   1108                                                                 renderer)

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in _update_ticks(self, renderer)
    947 
    948         interval = self.get_view_interval()
--> 949         tick_tups = [t for t in self.iter_ticks()]
    950         if self._smart_bounds:
    951             # handle inverted limits

C:\Anaconda2\lib\site-packages\matplotlib\axis.pyc in iter_ticks(self)
    890         Iterate through all of the major and minor ticks.
    891         """
--> 892         majorLocs = self.major.locator()
    893         majorTicks = self.get_major_ticks(len(majorLocs))
    894         self.major.formatter.set_locs(majorLocs)

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in __call__(self)
    901             vmin, vmax = vmax, vmin
    902         if self.isdynamic:
--> 903             locs = self._get_default_locs(vmin, vmax)
    904         else:  # pragma: no cover
    905             base = self.base

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in _get_default_locs(self, vmin, vmax)
    882 
    883         if self.plot_obj.date_axis_info is None:
--> 884             self.plot_obj.date_axis_info = self.finder(vmin, vmax, self.freq)
    885 
    886         locator = self.plot_obj.date_axis_info

C:\Anaconda2\lib\site-packages\pandas\tseries\converter.pyc in _daily_finder(vmin, vmax, freq)
    505                     Period(ordinal=int(vmax), freq=freq))
    506     span = vmax.ordinal - vmin.ordinal + 1
--> 507     dates_ = PeriodIndex(start=vmin, end=vmax, freq=freq)
    508     # Initialize the output
    509     info = np.zeros(span,

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in __new__(cls, data, ordinal, freq, start, end, periods, copy, name, tz, **kwargs)
    181             else:
    182                 data, freq = cls._generate_range(start, end, periods,
--> 183                                                  freq, kwargs)
    184         else:
    185             ordinal, freq = cls._from_arraylike(data, freq, tz)

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in _generate_range(cls, start, end, periods, freq, fields)
    195                 raise ValueError('Can either instantiate from fields '
    196                                  'or endpoints, but not both')
--> 197             subarr, freq = _get_ordinal_range(start, end, periods, freq)
    198         elif field_count > 0:
    199             subarr, freq = _range_from_fields(freq=freq, **fields)

C:\Anaconda2\lib\site-packages\pandas\tseries\period.pyc in _get_ordinal_range(start, end, periods, freq, mult)
    992                              dtype=np.int64)
    993     else:
--> 994         data = np.arange(start.ordinal, end.ordinal + 1, mult, dtype=np.int64)
    995 
    996     return data, freq

MemoryError: 

<matplotlib.figure.Figure at 0xdcbd1d0>

Interestingly, if I instead use

import matplotlib.pyploy as plt
plt.plot(df)

Then I actually get a plot, though the only column that shows anything on the graph is the bvp column, and it strangely has a 1e10 on the x-axis (even though, as mentioned above, the data series is only 3311 long and going up to 51.718750s).

enter image description here

Not too sure where to go from here. Any thoughts?

0 Answers
Related