|
4 | 4 | """ |
5 | 5 |
|
6 | 6 | # TODO: expose cap and join style attrs |
7 | | -from numbers import Number |
| 7 | +from numbers import Integral, Number, Real |
8 | 8 | import warnings |
9 | 9 |
|
10 | 10 | import numpy as np |
@@ -127,41 +127,37 @@ def _slice_or_none(in_v, slc): |
127 | 127 | return None |
128 | 128 | return in_v[slc] |
129 | 129 |
|
130 | | - # if just a float, assume starting at 0.0 and make a tuple |
131 | | - if isinstance(markevery, float): |
132 | | - markevery = (0.0, markevery) |
133 | 130 | # if just an int, assume starting at 0 and make a tuple |
134 | | - elif isinstance(markevery, int): |
| 131 | + if isinstance(markevery, Integral): |
135 | 132 | markevery = (0, markevery) |
136 | | - # if just an numpy int, assume starting at 0 and make a tuple |
137 | | - elif isinstance(markevery, np.integer): |
138 | | - markevery = (0, markevery.item()) |
| 133 | + # if just a float, assume starting at 0.0 and make a tuple |
| 134 | + elif isinstance(markevery, Real): |
| 135 | + markevery = (0.0, markevery) |
139 | 136 |
|
140 | 137 | if isinstance(markevery, tuple): |
141 | 138 | if len(markevery) != 2: |
142 | | - raise ValueError('`markevery` is a tuple but its ' |
143 | | - 'len is not 2; ' |
144 | | - 'markevery=%s' % (markevery,)) |
| 139 | + raise ValueError('`markevery` is a tuple but its len is not 2; ' |
| 140 | + 'markevery={}'.format(markevery)) |
145 | 141 | start, step = markevery |
146 | 142 | # if step is an int, old behavior |
147 | | - if isinstance(step, int): |
148 | | - #tuple of 2 int is for backwards compatibility, |
149 | | - if not(isinstance(start, int)): |
150 | | - raise ValueError('`markevery` is a tuple with ' |
151 | | - 'len 2 and second element is an int, but ' |
152 | | - 'the first element is not an int; ' |
153 | | - 'markevery=%s' % (markevery,)) |
| 143 | + if isinstance(step, Integral): |
| 144 | + # tuple of 2 int is for backwards compatibility, |
| 145 | + if not isinstance(start, Integral): |
| 146 | + raise ValueError( |
| 147 | + '`markevery` is a tuple with len 2 and second element is ' |
| 148 | + 'an int, but the first element is not an int; markevery={}' |
| 149 | + .format(markevery)) |
154 | 150 | # just return, we are done here |
155 | 151 |
|
156 | 152 | return Path(verts[slice(start, None, step)], |
157 | 153 | _slice_or_none(codes, slice(start, None, step))) |
158 | 154 |
|
159 | | - elif isinstance(step, float): |
160 | | - if not isinstance(start, (int, float)): |
| 155 | + elif isinstance(step, Real): |
| 156 | + if not isinstance(start, Real): |
161 | 157 | raise ValueError( |
162 | 158 | '`markevery` is a tuple with len 2 and second element is ' |
163 | 159 | 'a float, but the first element is not a float or an int; ' |
164 | | - 'markevery=%s' % (markevery,)) |
| 160 | + 'markevery={}'.format(markevery)) |
165 | 161 | # calc cumulative distance along path (in display coords): |
166 | 162 | disp_coords = affine.transform(tpath.vertices) |
167 | 163 | delta = np.empty((len(disp_coords), 2)) |
@@ -192,14 +188,12 @@ def _slice_or_none(in_v, slc): |
192 | 188 |
|
193 | 189 | elif isinstance(markevery, slice): |
194 | 190 | # mazol tov, it's already a slice, just return |
195 | | - return Path(verts[markevery], |
196 | | - _slice_or_none(codes, markevery)) |
| 191 | + return Path(verts[markevery], _slice_or_none(codes, markevery)) |
197 | 192 |
|
198 | 193 | elif iterable(markevery): |
199 | 194 | #fancy indexing |
200 | 195 | try: |
201 | | - return Path(verts[markevery], |
202 | | - _slice_or_none(codes, markevery)) |
| 196 | + return Path(verts[markevery], _slice_or_none(codes, markevery)) |
203 | 197 |
|
204 | 198 | except (ValueError, IndexError): |
205 | 199 | raise ValueError('`markevery` is iterable but ' |
@@ -822,7 +816,7 @@ def draw(self, renderer): |
822 | 816 | subsampled = tpath |
823 | 817 |
|
824 | 818 | snap = marker.get_snap_threshold() |
825 | | - if type(snap) == float: |
| 819 | + if isinstance(snap, Real): |
826 | 820 | snap = renderer.points_to_pixels(self._markersize) >= snap |
827 | 821 | gc.set_snap(snap) |
828 | 822 | gc.set_joinstyle(marker.get_joinstyle()) |
|
0 commit comments