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

ValueError if lines contain single elements #166

Open
fraseyboo opened this issue Oct 23, 2023 · 0 comments
Open

ValueError if lines contain single elements #166

fraseyboo opened this issue Oct 23, 2023 · 0 comments

Comments

@fraseyboo
Copy link

So this is probably a niche case but when this code is presented with a 'line' comprised of a singular point _update_anchors() throws a value error as it can't surround itself with valid line segment points. In this case it'd probably make more sense to set xa, xb ya & yb to the position of the point itself. The rest of the code still works fine with this change and the label appears normally.

I changed the code to the following, the index is unnecessary but I kept it for readability.

        # Find the first line segment surrounding x
        for i, (xa, xb) in enumerate(zip(xdata[:-1], xdata[1:])):
            if min(xa, xb) <= x <= max(xa, xb):
                ya, yb = ydata[i], ydata[i + 1]
                break
        else:
            i = 0
            ya, yb = ydata[i], ydata[i]
            xa, xb = xdata[i], xdata[i]
            # raise ValueError("x label location is outside data range!")

The code still throws a warning about the anchor position but it still completes fine, there might be a more intelligent way to handle this though.

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

1 participant