Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added labellines/baseline/test_nan_gaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions labellines/line_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def _update_anchors(self):
mask = np.isfinite(ydata)
if mask.sum() == 0:
raise ValueError(f"The line {self._line} only contains nan!")
xdata = xdata[mask]
ydata = ydata[mask]

# Find the first line segment surrounding x
for i, (xa, xb) in enumerate(zip(xdata[:-1], xdata[1:])):
Expand Down
14 changes: 14 additions & 0 deletions labellines/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ def test_nan_failure():
labelLine(line, 0.5)


@pytest.mark.mpl_image_compare
def test_nan_gaps(setup_mpl):
x = np.linspace(0, 10, 100)
x[10:30] = np.nan

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

labelLines(plt.gca().get_lines())

return plt.gcf()


@pytest.mark.mpl_image_compare
def test_label_range(setup_mpl):
x = np.linspace(0, 1)
Expand Down
Loading