Skip to content
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

errorbar fails with pandas data frame #5378

Closed
david-zwicker opened this issue Nov 2, 2015 · 3 comments
Closed

errorbar fails with pandas data frame #5378

david-zwicker opened this issue Nov 2, 2015 · 3 comments

Comments

@david-zwicker
Copy link

plt.errorbar seems to dislike pandas Dataframes since matplotlib 1.5.0.

Here is the full code:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plot

df = pd.DataFrame(np.random.rand(10, 2))
plt.errorbar(df[0], df[1], 'o')

which produces the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-8f3d736d3f20> in <module>()
----> 1 plt.errorbar(df[0], df[1], 'o')

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.pyc in errorbar(x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, hold, data, **kwargs)
   2828                           xlolims=xlolims, xuplims=xuplims,
   2829                           errorevery=errorevery, capthick=capthick, data=data,
-> 2830                           **kwargs)
   2831     finally:
   2832         ax.hold(washold)

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
   1809                     warnings.warn(msg % (label_namer, func.__name__),
   1810                                   RuntimeWarning, stacklevel=2)
-> 1811             return func(ax, *args, **kwargs)
   1812         pre_doc = inner.__doc__
   1813         if pre_doc is None:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
   2961                 # using list comps rather than arrays to preserve units
   2962                 lower = [thisy - thiserr for (thisy, thiserr)
-> 2963                          in cbook.safezip(y, yerr)]
   2964                 upper = [thisy + thiserr for (thisy, thiserr)
   2965                          in cbook.safezip(y, yerr)]

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.pyc in safezip(*args)
   1492     for i, arg in enumerate(args[1:]):
   1493         if len(arg) != Nx:
-> 1494             raise ValueError(_safezip_msg % (Nx, i + 1, len(arg)))
   1495     return list(zip(*args))
   1496 

ValueError: In safezip, len(args[0])=10 but len(args[1])=1

Interestingly, the code works if I replace errorbar by plot.

@tacaswell
Copy link
Member

This is not a pandas problem, mpl is trying to use 'o' as the yerr input which obviously does not work 😉 .

Try

plt.errorbar(df[0], df[1], marker='o')

@david-zwicker
Copy link
Author

Uhh, sorry, my mistake. I should have read the documentation more closely. Thanks for the quick help!

@tacaswell
Copy link
Member

No worries, the easy ones make me happy.

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

2 participants