Skip to content

Commit 2b0eb69

Browse files
authored
Merge pull request #35 from nschloe/nan
better nan handling in contour()
2 parents f4a56af + bd7d763 commit 2b0eb69

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/matplotx/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.5"
1+
__version__ = "0.3.6"

src/matplotx/_contour.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,13 @@ def _get_xy_paths(
145145
verti = np.ones((nx, ny - 1), dtype=bool)
146146

147147
if level is not None:
148-
# for each quad, check if the contour passes through it
148+
# For each quad, check if the contour passes through it.
149+
# Check `<` and `>=` separately to account for NaNs (for which both
150+
# comparisons are false.
149151
is_below = Z < level
150-
horiz &= ~np.logical_xor(is_below[:-1, :], ~is_below[1:, :])
151-
verti &= ~np.logical_xor(is_below[:, :-1], ~is_below[:, 1:])
152+
is_above = Z >= level
153+
horiz &= ~np.logical_xor(is_below[:-1, :], is_above[1:, :])
154+
verti &= ~np.logical_xor(is_below[:, :-1], is_above[:, 1:])
152155

153156
if min_jump is not None:
154157
horiz &= np.abs(Z[:-1, :] - Z[1:, :]) > min_jump

0 commit comments

Comments
 (0)