| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4031,9 +4031,8 @@ def do_plot(xs, ys, **kwargs): | |||
| 4031 | 4031 | return self.plot(*[xs, ys][maybe_swap], **kwargs)[0] | |
| 4032 | 4032 | ||
| 4033 | 4033 | def do_patch(xs, ys, **kwargs): | |
| 4034 | - path = mpath.Path( | ||
| 4035 | - # Last (0, 0) vertex has a CLOSEPOLY code and is thus ignored. | ||
| 4036 | - np.column_stack([[*xs, 0], [*ys, 0]][maybe_swap]), closed=True) | ||
| 4034 | + path = mpath.Path._create_closed( | ||
| 4035 | + np.column_stack([xs, ys][maybe_swap])) | ||
| 4037 | 4036 | patch = mpatches.PathPatch(path, **kwargs) | |
| 4038 | 4037 | self.add_artist(patch) | |
| 4039 | 4038 | return patch | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1217,11 +1217,7 @@ def set_verts(self, verts, closed=True): | |||
| 1217 | 1217 | self._paths = [] | |
| 1218 | 1218 | for xy in verts: | |
| 1219 | 1219 | if len(xy): | |
| 1220 | - if isinstance(xy, np.ma.MaskedArray): | ||
| 1221 | - xy = np.ma.concatenate([xy, xy[:1]]) | ||
| 1222 | - else: | ||
| 1223 | - xy = np.concatenate([xy, xy[:1]]) | ||
| 1224 | - self._paths.append(mpath.Path(xy, closed=True)) | ||
| 1220 | + self._paths.append(mpath.Path._create_closed(xy)) | ||
| 1225 | 1221 | else: | |
| 1226 | 1222 | self._paths.append(mpath.Path(xy)) | |
| 1227 | 1223 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,8 +195,7 @@ def _set_ticks_on_axis_warn(*args, **kwargs): | |||
| 195 | 195 | class _ColorbarSpine(mspines.Spine): | |
| 196 | 196 | def __init__(self, axes): | |
| 197 | 197 | self._ax = axes | |
| 198 | - super().__init__(axes, 'colorbar', | ||
| 199 | - mpath.Path(np.empty((0, 2)), closed=True)) | ||
| 198 | + super().__init__(axes, 'colorbar', mpath.Path(np.empty((0, 2)))) | ||
| 200 | 199 | mpatches.Patch.set_transform(self, axes.transAxes) | |
| 201 | 200 | ||
| 202 | 201 | def get_window_extent(self, renderer=None): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -571,15 +571,13 @@ def _set_pixel(self): | |||
| 571 | 571 | self._transform = Affine2D().translate(-0.49999, -0.49999) | |
| 572 | 572 | self._snap_threshold = None | |
| 573 | 573 | ||
| 574 | - _triangle_path = Path([[0, 1], [-1, -1], [1, -1], [0, 1]], closed=True) | ||
| 574 | + _triangle_path = Path._create_closed([[0, 1], [-1, -1], [1, -1]]) | ||
| 575 | 575 | # Going down halfway looks to small. Golden ratio is too far. | |
| 576 | - _triangle_path_u = Path([[0, 1], [-3/5, -1/5], [3/5, -1/5], [0, 1]], | ||
| 577 | - closed=True) | ||
| 578 | - _triangle_path_d = Path( | ||
| 579 | - [[-3/5, -1/5], [3/5, -1/5], [1, -1], [-1, -1], [-3/5, -1/5]], | ||
| 580 | - closed=True) | ||
| 581 | - _triangle_path_l = Path([[0, 1], [0, -1], [-1, -1], [0, 1]], closed=True) | ||
| 582 | - _triangle_path_r = Path([[0, 1], [0, -1], [1, -1], [0, 1]], closed=True) | ||
| 576 | + _triangle_path_u = Path._create_closed([[0, 1], [-3/5, -1/5], [3/5, -1/5]]) | ||
| 577 | + _triangle_path_d = Path._create_closed( | ||
| 578 | + [[-3/5, -1/5], [3/5, -1/5], [1, -1], [-1, -1]]) | ||
| 579 | + _triangle_path_l = Path._create_closed([[0, 1], [0, -1], [-1, -1]]) | ||
| 580 | + _triangle_path_r = Path._create_closed([[0, 1], [0, -1], [1, -1]]) | ||
| 583 | 581 | ||
| 584 | 582 | def _set_triangle(self, rot, skip): | |
| 585 | 583 | self._transform = Affine2D().scale(0.5).rotate_deg(rot) | |
@@ -901,14 +899,12 @@ def _set_x(self): | |||
| 901 | 899 | self._filled = False | |
| 902 | 900 | self._path = self._x_path | |
| 903 | 901 | ||
| 904 | - _plus_filled_path = Path( | ||
| 905 | - np.array([(-1, -3), (+1, -3), (+1, -1), (+3, -1), (+3, +1), (+1, +1), | ||
| 906 | - (+1, +3), (-1, +3), (-1, +1), (-3, +1), (-3, -1), (-1, -1), | ||
| 907 | - (-1, -3)]) / 6, closed=True) | ||
| 908 | - _plus_filled_path_t = Path( | ||
| 909 | - np.array([(+3, 0), (+3, +1), (+1, +1), (+1, +3), | ||
| 910 | - (-1, +3), (-1, +1), (-3, +1), (-3, 0), | ||
| 911 | - (+3, 0)]) / 6, closed=True) | ||
| 902 | + _plus_filled_path = Path._create_closed(np.array([ | ||
| 903 | + (-1, -3), (+1, -3), (+1, -1), (+3, -1), (+3, +1), (+1, +1), | ||
| 904 | + (+1, +3), (-1, +3), (-1, +1), (-3, +1), (-3, -1), (-1, -1)]) / 6) | ||
| 905 | + _plus_filled_path_t = Path._create_closed(np.array([ | ||
| 906 | + (+3, 0), (+3, +1), (+1, +1), (+1, +3), | ||
| 907 | + (-1, +3), (-1, +1), (-3, +1), (-3, 0)]) / 6) | ||
| 912 | 908 | ||
| 913 | 909 | def _set_plus_filled(self): | |
| 914 | 910 | self._transform = Affine2D() | |
@@ -924,15 +920,12 @@ def _set_plus_filled(self): | |||
| 924 | 920 | {'top': 0, 'left': 90, 'bottom': 180, 'right': 270}[fs]) | |
| 925 | 921 | self._alt_transform = self._transform.frozen().rotate_deg(180) | |
| 926 | 922 | ||
| 927 | - _x_filled_path = Path( | ||
| 928 | - np.array([(-1, -2), (0, -1), (+1, -2), (+2, -1), (+1, 0), (+2, +1), | ||
| 929 | - (+1, +2), (0, +1), (-1, +2), (-2, +1), (-1, 0), (-2, -1), | ||
| 930 | - (-1, -2)]) / 4, | ||
| 931 | - closed=True) | ||
| 932 | - _x_filled_path_t = Path( | ||
| 933 | - np.array([(+1, 0), (+2, +1), (+1, +2), (0, +1), | ||
| 934 | - (-1, +2), (-2, +1), (-1, 0), (+1, 0)]) / 4, | ||
| 935 | - closed=True) | ||
| 923 | + _x_filled_path = Path._create_closed(np.array([ | ||
| 924 | + (-1, -2), (0, -1), (+1, -2), (+2, -1), (+1, 0), (+2, +1), | ||
| 925 | + (+1, +2), (0, +1), (-1, +2), (-2, +1), (-1, 0), (-2, -1)]) / 4) | ||
| 926 | + _x_filled_path_t = Path._create_closed(np.array([ | ||
| 927 | + (+1, 0), (+2, +1), (+1, +2), (0, +1), | ||
| 928 | + (-1, +2), (-2, +1), (-1, 0)]) / 4) | ||
| 936 | 929 | ||
| 937 | 930 | def _set_x_filled(self): | |
| 938 | 931 | self._transform = Affine2D() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1269,11 +1269,9 @@ class Arrow(Patch): | |||
| 1269 | 1269 | def __str__(self): | |
| 1270 | 1270 | return "Arrow()" | |
| 1271 | 1271 | ||
| 1272 | - _path = Path([[0.0, 0.1], [0.0, -0.1], | ||
| 1273 | - [0.8, -0.1], [0.8, -0.3], | ||
| 1274 | - [1.0, 0.0], [0.8, 0.3], | ||
| 1275 | - [0.8, 0.1], [0.0, 0.1]], | ||
| 1276 | - closed=True) | ||
| 1272 | + _path = Path._create_closed([ | ||
| 1273 | + [0.0, 0.1], [0.0, -0.1], [0.8, -0.1], [0.8, -0.3], [1.0, 0.0], | ||
| 1274 | + [0.8, 0.3], [0.8, 0.1]]) | ||
| 1277 | 1275 | ||
| 1278 | 1276 | @_docstring.dedent_interpd | |
| 1279 | 1277 | @_api.make_keyword_only("3.6", name="width") | |
@@ -2303,8 +2301,8 @@ def __call__(self, x0, y0, width, height, mutation_size): | |||
| 2303 | 2301 | # boundary of the padded box | |
| 2304 | 2302 | x0, y0 = x0 - pad, y0 - pad | |
| 2305 | 2303 | x1, y1 = x0 + width, y0 + height | |
| 2306 | - return Path([(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)], | ||
| 2307 | - closed=True) | ||
| 2304 | + return Path._create_closed( | ||
| 2305 | + [(x0, y0), (x1, y0), (x1, y1), (x0, y1)]) | ||
| 2308 | 2306 | ||
| 2309 | 2307 | @_register_style(_style_list) | |
| 2310 | 2308 | class Circle: | |
@@ -2353,11 +2351,11 @@ def __call__(self, x0, y0, width, height, mutation_size): | |||
| 2353 | 2351 | dxx = dx / 2 | |
| 2354 | 2352 | x0 = x0 + pad / 1.4 # adjust by ~sqrt(2) | |
| 2355 | 2353 | ||
| 2356 | - return Path([(x0 + dxx, y0), (x1, y0), (x1, y1), (x0 + dxx, y1), | ||
| 2357 | - (x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx), | ||
| 2358 | - (x0 + dxx, y0 - dxx), # arrow | ||
| 2359 | - (x0 + dxx, y0), (x0 + dxx, y0)], | ||
| 2360 | - closed=True) | ||
| 2354 | + return Path._create_closed( | ||
| 2355 | + [(x0 + dxx, y0), (x1, y0), (x1, y1), (x0 + dxx, y1), | ||
| 2356 | + (x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx), | ||
| 2357 | + (x0 + dxx, y0 - dxx), # arrow | ||
| 2358 | + (x0 + dxx, y0)]) | ||
| 2361 | 2359 | ||
| 2362 | 2360 | @_register_style(_style_list) | |
| 2363 | 2361 | class RArrow(LArrow): | |
@@ -2397,14 +2395,14 @@ def __call__(self, x0, y0, width, height, mutation_size): | |||
| 2397 | 2395 | dxx = dx / 2 | |
| 2398 | 2396 | x0 = x0 + pad / 1.4 # adjust by ~sqrt(2) | |
| 2399 | 2397 | ||
| 2400 | - return Path([(x0 + dxx, y0), (x1, y0), # bot-segment | ||
| 2401 | - (x1, y0 - dxx), (x1 + dx + dxx, y0 + dx), | ||
| 2402 | - (x1, y1 + dxx), # right-arrow | ||
| 2403 | - (x1, y1), (x0 + dxx, y1), # top-segment | ||
| 2404 | - (x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx), | ||
| 2405 | - (x0 + dxx, y0 - dxx), # left-arrow | ||
| 2406 | - (x0 + dxx, y0), (x0 + dxx, y0)], # close-poly | ||
| 2407 | - closed=True) | ||
| 2398 | + return Path._create_closed([ | ||
| 2399 | + (x0 + dxx, y0), (x1, y0), # bot-segment | ||
| 2400 | + (x1, y0 - dxx), (x1 + dx + dxx, y0 + dx), | ||
| 2401 | + (x1, y1 + dxx), # right-arrow | ||
| 2402 | + (x1, y1), (x0 + dxx, y1), # top-segment | ||
| 2403 | + (x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx), | ||
| 2404 | + (x0 + dxx, y0 - dxx), # left-arrow | ||
| 2405 | + (x0 + dxx, y0)]) | ||
| 2408 | 2406 | ||
| 2409 | 2407 | @_register_style(_style_list) | |
| 2410 | 2408 | class Round: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,6 +188,17 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None): | |||
| 188 | 188 | pth._interpolation_steps = 1 | |
| 189 | 189 | return pth | |
| 190 | 190 | ||
| 191 | + @classmethod | ||
| 192 | + def _create_closed(cls, vertices): | ||
| 193 | + """ | ||
| 194 | + Create a closed polygonal path going through *vertices*. | ||
| 195 | + | ||
| 196 | + Unlike ``Path(..., closed=True)``, *vertices* should **not** end with | ||
| 197 | + an entry for the CLOSEPATH; this entry is added by `._create_closed`. | ||
| 198 | + """ | ||
| 199 | + v = _to_unmasked_float_array(vertices) | ||
| 200 | + return cls(np.concatenate([v, v[:1]]), closed=True) | ||
| 201 | + | ||
| 191 | 202 | def _update_values(self): | |
| 192 | 203 | self._simplify_threshold = mpl.rcParams['path.simplify_threshold'] | |
| 193 | 204 | self._should_simplify = ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -296,7 +296,7 @@ def test_marker_as_markerstyle(): | |||
| 296 | 296 | line.set_marker(MarkerStyle("o")) | |
| 297 | 297 | fig.canvas.draw() | |
| 298 | 298 | # test Path roundtrip | |
| 299 | - triangle1 = Path([[-1., -1.], [1., -1.], [0., 2.], [0., 0.]], closed=True) | ||
| 299 | + triangle1 = Path._create_closed([[-1, -1], [1, -1], [0, 2]]) | ||
| 300 | 300 | line2, = ax.plot([1, 3, 2], marker=MarkerStyle(triangle1), ms=22) | |
| 301 | 301 | line3, = ax.plot([0, 2, 1], marker=triangle1, ms=22) | |
| 302 | 302 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,9 +53,7 @@ def test_path_exceptions(): | |||
| 53 | 53 | ||
| 54 | 54 | def test_point_in_path(): | |
| 55 | 55 | # Test #1787 | |
| 56 | - verts2 = [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)] | ||
| 57 | - | ||
| 58 | - path = Path(verts2, closed=True) | ||
| 56 | + path = Path._create_closed([(0, 0), (0, 1), (1, 1), (1, 0)]) | ||
| 59 | 57 | points = [(0.5, 0.5), (1.5, 0.5)] | |
| 60 | 58 | ret = path.contains_points(points) | |
| 61 | 59 | assert ret.dtype == 'bool' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,8 +191,7 @@ def test_affine_inverted_invalidated(): | |||
| 191 | 191 | ||
| 192 | 192 | def test_clipping_of_log(): | |
| 193 | 193 | # issue 804 | |
| 194 | - path = Path([(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99)], | ||
| 195 | - closed=True) | ||
| 194 | + path = Path._create_closed([(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20)]) | ||
| 196 | 195 | # something like this happens in plotting logarithmic histograms | |
| 197 | 196 | trans = mtransforms.BlendedGenericTransform( | |
| 198 | 197 | mtransforms.Affine2D(), scale.LogTransform(10, 'clip')) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,8 +160,7 @@ def __init__(self, bbox, **kwargs): | |||
| 160 | 160 | def get_path(self): | |
| 161 | 161 | # docstring inherited | |
| 162 | 162 | x0, y0, x1, y1 = self.bbox.extents | |
| 163 | - return Path([(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)], | ||
| 164 | - closed=True) | ||
| 163 | + return Path._create_closed([(x0, y0), (x1, y0), (x1, y1), (x0, y1)]) | ||
| 165 | 164 | ||
| 166 | 165 | ||
| 167 | 166 | class BboxConnector(Patch): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments