Skip to content

Commit b73d805

Browse files
allow numpy arrays in markevery
1 parent 6cd24b9 commit b73d805

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/matplotlib/lines.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def set_markevery(self, every):
537537
Parameters
538538
----------
539539
every : None or int or (int, int) or slice or List[int] or float or \
540-
(float, float)
540+
(float, float) or List[bool]
541541
Which markers to plot.
542542
543543
- every=None, every point will be plotted.
@@ -549,6 +549,8 @@ def set_markevery(self, every):
549549
point start, up to but not including point end, will be plotted.
550550
- every=[i, j, m, n], only markers at points i, j, m, and n
551551
will be plotted.
552+
- every=[True, False, True], positions that are True will be
553+
plotted.
552554
- every=0.1, (i.e. a float) then markers will be spaced at
553555
approximately equal distances along the line; the distance
554556
along the line between markers is determined by multiplying the
@@ -580,9 +582,8 @@ def set_markevery(self, every):
580582
axes-bounding-box-diagonal regardless of the actual axes data limits.
581583
582584
"""
583-
if self._markevery != every:
584-
self.stale = True
585585
self._markevery = every
586+
self.stale = True
586587

587588
def get_markevery(self):
588589
"""

lib/matplotlib/tests/test_lines.py

+24
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,30 @@ def test_step_markers(fig_test, fig_ref):
199199
fig_ref.subplots().plot([0, 0, 1], [0, 1, 1], "-o", markevery=[0, 2])
200200

201201

202+
@check_figures_equal(extensions=('png',))
203+
def test_markevery(fig_test, fig_ref):
204+
np.random.seed(42)
205+
t = np.linspace(0, 3, 14)
206+
y = np.random.rand(len(t))
207+
208+
casesA = [None, 4, (2, 5), [1, 5, 11],
209+
[0, -1], slice(5, 10, 2), 0.3, (0.3, 0.4),
210+
np.arange(len(t))[y > 0.5]]
211+
casesB = ["11111111111111", "10001000100010", "00100001000010",
212+
"01000100000100", "10000000000001", "00000101010000",
213+
"11011011011110", "01010011011101", "01110001110110"]
214+
215+
axsA = fig_ref.subplots(3, 3)
216+
axsB = fig_test.subplots(3, 3)
217+
218+
for ax, case in zip(axsA.flat, casesA):
219+
ax.plot(t, y, "-gD", markevery=case)
220+
221+
for ax, case in zip(axsB.flat, casesB):
222+
me = np.array(list(case)).astype(int).astype(bool)
223+
ax.plot(t, y, "-gD", markevery=me)
224+
225+
202226
def test_marker_as_markerstyle():
203227
fig, ax = plt.subplots()
204228
line, = ax.plot([2, 4, 3], marker=MarkerStyle("D"))

0 commit comments

Comments
 (0)