Skip to content

Commit 3a3d52c

Browse files
committed
improve markers distribution by using averages of values next to nans
1 parent 9baf774 commit 3a3d52c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/matplotlib/lines.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,23 @@ def _slice_or_none(in_v, slc):
159159
"markevery is specified relative to the axes size, but "
160160
"the line does not have a Axes as parent")
161161
# calc cumulative distance along path (in display coords):
162-
aux = np.where(np.isfinite(tpath.vertices), tpath.vertices,
163-
np.nanmean(tpath.vertices, axis=0))
162+
mask = np.isnan(tpath.vertices)
163+
if mask.any():
164+
aux = np.empty_like(tpath.vertices)
165+
for ic, vals in enumerate(tpath.vertices.T):
166+
ok = ~mask[:, ic]
167+
ii = np.where(ok, np.arange(ok.shape[0]), -1)
168+
i0, i1 = np.nonzero(ok)[0][[0, -1]]
169+
ii[:i0] = i0
170+
ilo = np.maximum.accumulate(ii)
171+
ii[mask[:, ic]] = ok.shape[0] - 1
172+
ii[i1:] = i1
173+
ihi = np.minimum.accumulate(ii[::-1])[::-1]
174+
aux[:, ic] = 0.5 * (vals[ilo] + vals[ihi])
175+
176+
else:
177+
aux = tpath.vertices
178+
164179
disp_coords = affine.transform(aux)
165180
delta = np.empty((len(disp_coords), 2))
166181
delta[0, :] = 0

0 commit comments

Comments
 (0)