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

Graph with gaps (NaNs) causing Error #209

Closed
Vasco-Da-Gama-png opened this issue Mar 7, 2025 · 2 comments
Closed

Graph with gaps (NaNs) causing Error #209

Vasco-Da-Gama-png opened this issue Mar 7, 2025 · 2 comments

Comments

@Vasco-Da-Gama-png
Copy link

When you have a graph with gaps in it and labellines tries to label the line in the gap, this causes the following error:
ValueError: x label location is outside data range!

Here is a photo of an example plot:
Image

@scottshambaugh
Copy link
Contributor

I can reproduce with this script:

import matplotlib.pyplot as plt
import numpy as np
from labellines import labelLines

x = np.linspace(0, 10, 100)
x[10:30] = np.nan

fig, ax = plt.subplots()

for i in range(10):
    y = np.sin(x + i)
    ax.plot(x, y, label=f'y={i}')

labelLines(ax.get_lines(), zorder=2.5)

plt.show(block=True)

@Vasco-Da-Gama-png it looks like you're using a datetime axis, once #210 is merged in you'll be able to work around this by manually setting label locations with the xvals argument.

@cphyc
Copy link
Owner

cphyc commented Mar 7, 2025

Closed by #211 and #212.

@cphyc cphyc closed this as completed Mar 7, 2025
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