Skip to content

Errors in example plots in documentation #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
michaelnt opened this issue Jan 16, 2012 · 3 comments
Closed

Errors in example plots in documentation #634

michaelnt opened this issue Jan 16, 2012 · 3 comments

Comments

@michaelnt
Copy link

This page has exceptions thrown for the some of the examples. I've tried running the example and it works fine so I guess a problem with how the documents were generated.

http://pandas.sourceforge.net/visualization.html#basic-plotting-plot

The following page talks about version 0.4 and this new feature so perhaps it should be updated now that 0.7 has been released.

http://pandas.sourceforge.net/indexing.html#indexing-hierarchical

@wesm wesm closed this as completed Jan 16, 2012
@wesm wesm reopened this Jan 16, 2012
@lodagro
Copy link
Contributor

lodagro commented Jan 17, 2012

Tried also to run first example, gave same error as in documentation though.

In [1]: cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:   import numpy as np
:   np.random.seed(123456)
:   from pandas import *
:   import pandas.util.testing as tm
:   randn = np.random.randn
:   np.set_printoptions(precision=4, suppress=True)
:   import matplotlib.pyplot as plt
:   plt.close('all')
:--

In [2]: ts = Series(randn(1000), index=DateRange('1/1/2000', periods=1000))

In [3]: ts = ts.cumsum()

In [4]: ts.plot()
Out[4]: <matplotlib.axes.AxesSubplot at 0x14446690>

In [5]: df = DataFrame(randn(1000, 4), index=ts.index, columns=['A', 'B', 'C', 'D'])

In [6]: df = df.cumsum()

In [7]: df.plot()
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-7-4f76bcc16520> in <module>()
----> 1 df.plot()

.../lib/python2.7/site-packages/pandas-0.7.0.dev_195ec30-py2.7-linux-x86_64.egg/pandas/core/frame.pyc in plot(self, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, kind, **kwds)
   3566                     msg = ('Unable to plot data %s vs index %s,\n'
   3567                            'error was: %s' % (str(y), str(x), str(e)))
-> 3568                     raise Exception(msg)
   3569
   3570                 ax.grid(grid)

Exception: Unable to plot data [ -0.2185  -0.7162  -1.2592  -1.8215  -3.5141  -3.6892  -5.3315  -4.7415
 ...
 -15.9591 -16.2024 -16.2647 -18.3865 -18.6017 -18.4403 -19.1776 -19.4117] vs index <class 'pandas.core.daterange.DateRange'>
offset: <1 BusinessDay>, tzinfo: None
[2000-01-03 00:00:00, ..., 2003-10-31 00:00:00]
length: 1000,
error was: Buffer has wrong number of dimensions (expected 1, got 2)

Looks like it is related to the index

In [8]: df = DataFrame(randn(1000, 4), columns=['A', 'B', 'C', 'D'])

In [9]: df = df.cumsum()

In [10]: df.plot()
Out[10]: <matplotlib.axes.AxesSubplot at 0x14dfb750>

In[11]:

@lodagro
Copy link
Contributor

lodagro commented Jan 17, 2012

Changing only one line, makes it run fine.

diff --git a/pandas/core/frame.py b/pandas/core/frame.py
index c881553..c5d5b5f 100644
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -3547,7 +3547,7 @@ class DataFrame(NDFrame):

         if kind == 'line':
             if use_index:
-                x = self.index
+                x = np.asarray(self.index)
             else:
                 x = range(len(self))

@wesm
Copy link
Member

wesm commented Jan 17, 2012

This got fixed in #635

@wesm wesm closed this as completed Jan 17, 2012
dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
Fixed small bug in DateRange.intersection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants