Skip to content

"Error: local variable 'xdata' referenced before assignment" in legend_handler.py #6921

Closed
@pfaion

Description

@pfaion

Hi everyone,
I made a stupid typo and generated a legend for my plot with half a numpoint

plt.legend(numpoints = 0.5)

which obviously makes no sense. But finding the error took some time due to the stupid error message and the original issue not being handles correctly here:

https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/legend_handler.py#L151

If you check for being an integer in the if-statement and throw a more readable error if not (e.g. "Number of points has to be an integer", or similar) that would be great.

Cheers
Patrick

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions