Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83a8420

Browse filesBrowse files
committed
added markevery property to Line2D
svn path=/trunk/matplotlib/; revision=6631
1 parent c53030d commit 83a8420
Copy full SHA for 83a8420

4 files changed

+73-2Lines changed: 73 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CHANGELOG‎

Copy file name to clipboardExpand all lines: CHANGELOG
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-12-16 Added markevery property to Line2D to support subsampling
2+
of markers - JDH
3+
14
2008-12-15 Removed mpl_data symlink in docs. On platforms that do not
25
support symlinks, these become copies, and the font files
36
are large, so the distro becomes unneccessarily bloaded.
Collapse file

‎doc/users/pyplot_tutorial.rst‎

Copy file name to clipboardExpand all lines: doc/users/pyplot_tutorial.rst
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ markeredgecolor or mec any matplotlib color
117117
markeredgewidth or mew float value in points
118118
markerfacecolor or mfc any matplotlib color
119119
markersize or ms float
120+
markevery None | integer | (startind, stride)
120121
picker used in interactive line selection
121122
pickradius the line pick selection radius
122123
solid_capstyle ['butt' | 'round' | 'projecting']
Collapse file

‎lib/matplotlib/lines.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/lines.py
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def __init__(self, xdata, ydata,
177177
solid_joinstyle = None,
178178
pickradius = 5,
179179
drawstyle = None,
180+
markevery = None,
180181
**kwargs
181182
):
182183
"""
@@ -226,6 +227,7 @@ def __init__(self, xdata, ydata,
226227
self.set_linewidth(linewidth)
227228
self.set_color(color)
228229
self.set_marker(marker)
230+
self.set_markevery(markevery)
229231
self.set_antialiased(antialiased)
230232
self.set_markersize(markersize)
231233
self._dashSeq = None
@@ -320,6 +322,32 @@ def setpickradius(self,d):
320322
"""
321323
self.pickradius = d
322324

325+
326+
def set_markevery(self, every):
327+
"""
328+
Set the markevery property to subsample the plot when using
329+
markers. Eg if ``markevery=5``, every 5-th marker will be
330+
plotted. *every* can be
331+
332+
None
333+
Every point will be plotted
334+
335+
an integer N
336+
Every N-th marker will be plotted starting with marker 0
337+
338+
A length-2 tuple of integers
339+
every=(start, N) will start at point start and plot every N-th marker
340+
341+
342+
ACCEPTS: None | integer | (startind, stride)
343+
344+
"""
345+
self._markevery = every
346+
347+
def get_markevery(self):
348+
'return the markevery setting'
349+
return self._markevery
350+
323351
def set_picker(self,p):
324352
"""Sets the event picker details for the line.
325353
@@ -472,6 +500,19 @@ def draw(self, renderer):
472500
funcname = self._markers.get(self._marker, '_draw_nothing')
473501
if funcname != '_draw_nothing':
474502
tpath, affine = self._transformed_path.get_transformed_points_and_affine()
503+
504+
# subsample the markers if markevery is not None
505+
markevery = self.get_markevery()
506+
if markevery is not None:
507+
if iterable(markevery):
508+
startind, stride = markevery
509+
else:
510+
startind, stride = 0, markevery
511+
if tpath.codes is not None:
512+
tpath.codes = tpath.codes[startind::stride]
513+
tpath.vertices = tpath.vertices[startind::stride]
514+
515+
475516
markerFunc = getattr(self, funcname)
476517
markerFunc(renderer, gc, tpath, affine.frozen())
477518

Collapse file

‎unit/nose_tests.py‎

Copy file name to clipboard
+28-2Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1+
import numpy as np
2+
13
import nose, nose.tools as nt
24
import numpy.testing as nptest
35

46
import matplotlib
57
matplotlib.use('Agg')
6-
import numpy as np
78
import matplotlib.pyplot as plt
89
import matplotlib.axes as maxes
910

1011
def test_create_subplot_object():
1112
fig = plt.figure()
1213
ax = maxes.Subplot(fig, 1, 1, 1)
1314
fig.add_subplot(ax)
15+
plt.close(fig)
16+
17+
def test_markevery():
18+
x, y = np.random.rand(2, 100)
19+
20+
# check marker only plot
21+
fig = plt.figure()
22+
ax = fig.add_subplot(111)
23+
ax.plot(x, y, 'o')
24+
ax.plot(x, y, 'd', markevery=None)
25+
ax.plot(x, y, 's', markevery=10)
26+
ax.plot(x, y, '+', markevery=(5, 20))
27+
fig.canvas.draw()
28+
plt.close(fig)
29+
30+
# check line/marker combos
31+
fig = plt.figure()
32+
ax = fig.add_subplot(111)
33+
ax.plot(x, y, '-o')
34+
ax.plot(x, y, '-d', markevery=None)
35+
ax.plot(x, y, '-s', markevery=10)
36+
ax.plot(x, y, '-+', markevery=(5, 20))
37+
fig.canvas.draw()
38+
plt.close(fig)
1439

1540
if __name__=='__main__':
1641
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
17-
pass
42+
43+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.