Skip to content

Problem with Series.plot #97

Closed
Closed
@dieterv77

Description

@dieterv77

The code snippet below raises an AssertionError from pandas because matplotlib tries to add a dimension to the index ndarray subclass.
No big deal, since i can do
pylab.plot(np.asarray(ts.index), np.asarray(ts.values)

import pandas
import datetime
import numpy as np
values = np.arange(5.)
dates = [datetime.datetime(2009, 1, 1, 0, 0),
datetime.datetime(2009, 1, 2, 0, 0),
datetime.datetime(2009, 1, 5, 0, 0),
datetime.datetime(2009, 1, 6, 0, 0),
datetime.datetime(2009, 1, 7, 0, 0)]
ts = pandas.Series(values, index=dates)
ts.plot()

Here's the trace back:
Traceback (most recent call last):
File "pandasplot.py", line 11, in
ts.plot()
File "/usr/lib/python2.7/dist-packages/pandas/core/series.py", line 1189, in plot
ax.plot(x, self.values.astype(float), style, *_kwds)
File "/usr/lib/python2.7/dist-packages/matplotlib/axes.py", line 3783, in plot
for line in self._get_lines(_args, **kwargs):
File "/usr/lib/python2.7/dist-packages/matplotlib/axes.py", line 317, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "/usr/lib/python2.7/dist-packages/matplotlib/axes.py", line 294, in _plot_args
x, y = self._xy_from_xy(x, y)
File "/usr/lib/python2.7/dist-packages/matplotlib/axes.py", line 239, in _xy_from_xy
x = x[:,np.newaxis]
File "/usr/lib/python2.7/dist-packages/pandas/core/index.py", line 110, in getitem
return Index(arr_idx[key])
File "/usr/lib/python2.7/dist-packages/pandas/core/index.py", line 50, in new
assert(subarr.ndim == 1)
AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions