Skip to content

Index without 0 in xerr/yerr causes KeyError #11858

Closed
@diazona

Description

@diazona

When creating an errorbar plot, if the data object being used for the errors (xerr or yerr) doesn't have 0 in its index, it produces a KeyError from matplotlib code. I can produce this with the following code sample:

import pandas as pd, numpy as np
i = np.array([1,2,3])
a = pd.DataFrame(i, index=i)
a.plot(yerr=a)

The underlying bug (if it is a bug) in matplotlib is responsible for several other issues, including #4493 and #6127, but this case is different because it uses only Pandas API methods, rather than passing a Pandas object to a matplotlib method. So it's a little harder to justify passing this off on matplotlib to fix, as was done in e.g. #6127.

If the "proper" fix ever is implemented in matplotlib code, it should solve this as well as #4493 and #6127 and all the others of that nature, but until that point, Pandas can work around it by converting the error object (if it is a Series or DataFrame) to an ndarray. I'm working on this in 4b04f80 but I'm not sure if there's a better way to fix it, or if this breaks something. (If so, the tests don't indicate it.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions