-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add hatchcolor parameter for Collections #29044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
d7da1fc
2fd17a0
f5978ce
5377127
6f18c49
8a7cd65
e3b03fc
7668535
9d0ec23
7e46707
c5e9583
d2b6268
fee895b
b9ac0fb
2e4784b
3b43bc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -208,7 +208,7 @@ | |||||
| def draw_path_collection(self, gc, master_transform, paths, all_transforms, | ||||||
| offsets, offset_trans, facecolors, edgecolors, | ||||||
| linewidths, linestyles, antialiaseds, urls, | ||||||
| offset_position): | ||||||
| offset_position, *, hatchcolors=None): | ||||||
| """ | ||||||
| Draw a collection of *paths*. | ||||||
|
|
||||||
|
|
@@ -217,8 +217,11 @@ | |||||
| *master_transform*. They are then translated by the corresponding | ||||||
| entry in *offsets*, which has been first transformed by *offset_trans*. | ||||||
|
|
||||||
| *facecolors*, *edgecolors*, *linewidths*, *linestyles*, and | ||||||
| *antialiased* are lists that set the corresponding properties. | ||||||
| *facecolors*, *edgecolors*, *linewidths*, *linestyles*, *antialiased* | ||||||
| and *hatchcolors* are lists that set the corresponding properties. | ||||||
|
timhoffm marked this conversation as resolved.
|
||||||
|
|
||||||
| .. versionadded:: 3.11 | ||||||
| Allowing *hatchcolors* to be specified. | ||||||
|
timhoffm marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| *offset_position* is unused now, but the argument is kept for | ||||||
| backwards compatibility. | ||||||
|
|
@@ -235,10 +238,13 @@ | |||||
| path_ids = self._iter_collection_raw_paths(master_transform, | ||||||
| paths, all_transforms) | ||||||
|
|
||||||
| if hatchcolors is None: | ||||||
| hatchcolors = [] | ||||||
|
Impaler343 marked this conversation as resolved.
|
||||||
|
|
||||||
| for xo, yo, path_id, gc0, rgbFace in self._iter_collection( | ||||||
| gc, list(path_ids), offsets, offset_trans, | ||||||
| facecolors, edgecolors, linewidths, linestyles, | ||||||
| antialiaseds, urls, offset_position): | ||||||
| antialiaseds, urls, offset_position, hatchcolors): | ||||||
| path, transform = path_id | ||||||
| # Only apply another translation if we have an offset, else we | ||||||
| # reuse the initial transform. | ||||||
|
|
@@ -252,7 +258,7 @@ | |||||
|
|
||||||
| def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight, | ||||||
| coordinates, offsets, offsetTrans, facecolors, | ||||||
| antialiased, edgecolors): | ||||||
| antialiased, edgecolors, hatchcolors=None): | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Should we make this keyword only here, like it is in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a red herring? From what I understand from #29044 (comment), making hatchcolors optional (or even kw-only) does not buy us anything in terms of better API compatibility: This is reimplemented by backends. Some may have implemented a If that's correct, an additional positional parameter would have the same effect. And then I'd prefer that because it keeps the whole function consistent. ping @anntzer Am I correct here? Edit: There seem to be very few "real" usages of I think making this optional is meaningful for a start because it will support some very rare use cases. But in terms of API consistency, I'd like to move this to a regular parameter in the future, i.e.
|
||||||
| """ | ||||||
| Draw a quadmesh. | ||||||
|
|
||||||
|
|
@@ -265,11 +271,14 @@ | |||||
|
|
||||||
| if edgecolors is None: | ||||||
| edgecolors = facecolors | ||||||
| if hatchcolors is None: | ||||||
| hatchcolors = [] | ||||||
|
Impaler343 marked this conversation as resolved.
|
||||||
| linewidths = np.array([gc.get_linewidth()], float) | ||||||
|
|
||||||
| return self.draw_path_collection( | ||||||
| gc, master_transform, paths, [], offsets, offsetTrans, facecolors, | ||||||
| edgecolors, linewidths, [], [antialiased], [None], 'screen') | ||||||
| edgecolors, linewidths, [], [antialiased], [None], 'screen', | ||||||
| hatchcolors=hatchcolors) | ||||||
|
|
||||||
| def draw_gouraud_triangles(self, gc, triangles_array, colors_array, | ||||||
| transform): | ||||||
|
|
@@ -337,7 +346,7 @@ | |||||
|
|
||||||
| def _iter_collection(self, gc, path_ids, offsets, offset_trans, facecolors, | ||||||
| edgecolors, linewidths, linestyles, | ||||||
| antialiaseds, urls, offset_position): | ||||||
| antialiaseds, urls, offset_position, hatchcolors): | ||||||
|
Impaler343 marked this conversation as resolved.
Outdated
|
||||||
| """ | ||||||
| Helper method (along with `_iter_collection_raw_paths`) to implement | ||||||
| `draw_path_collection` in a memory-efficient manner. | ||||||
|
|
@@ -365,11 +374,12 @@ | |||||
| N = max(Npaths, Noffsets) | ||||||
| Nfacecolors = len(facecolors) | ||||||
| Nedgecolors = len(edgecolors) | ||||||
| Nhatchcolors = len(hatchcolors) | ||||||
| Nlinewidths = len(linewidths) | ||||||
| Nlinestyles = len(linestyles) | ||||||
| Nurls = len(urls) | ||||||
|
|
||||||
| if (Nfacecolors == 0 and Nedgecolors == 0) or Npaths == 0: | ||||||
| if (Nfacecolors == 0 and Nedgecolors == 0 and Nhatchcolors == 0) or Npaths == 0: | ||||||
| return | ||||||
|
|
||||||
| gc0 = self.new_gc() | ||||||
|
|
@@ -384,6 +394,7 @@ | |||||
| toffsets = cycle_or_default(offset_trans.transform(offsets), (0, 0)) | ||||||
| fcs = cycle_or_default(facecolors) | ||||||
| ecs = cycle_or_default(edgecolors) | ||||||
| hcs = cycle_or_default(hatchcolors) | ||||||
| lws = cycle_or_default(linewidths) | ||||||
| lss = cycle_or_default(linestyles) | ||||||
| aas = cycle_or_default(antialiaseds) | ||||||
|
|
@@ -392,8 +403,8 @@ | |||||
| if Nedgecolors == 0: | ||||||
| gc0.set_linewidth(0.0) | ||||||
|
|
||||||
| for pathid, (xo, yo), fc, ec, lw, ls, aa, url in itertools.islice( | ||||||
| zip(pathids, toffsets, fcs, ecs, lws, lss, aas, urls), N): | ||||||
| for pathid, (xo, yo), fc, ec, hc, lw, ls, aa, url in itertools.islice( | ||||||
| zip(pathids, toffsets, fcs, ecs, hcs, lws, lss, aas, urls), N): | ||||||
| if not (np.isfinite(xo) and np.isfinite(yo)): | ||||||
| continue | ||||||
| if Nedgecolors: | ||||||
|
|
@@ -405,6 +416,8 @@ | |||||
| gc0.set_linewidth(0) | ||||||
| else: | ||||||
| gc0.set_foreground(ec) | ||||||
| if Nhatchcolors: | ||||||
| gc0.set_hatch_color(hc) | ||||||
| if fc is not None and len(fc) == 4 and fc[3] == 0: | ||||||
| fc = None | ||||||
| gc0.set_antialiased(aa) | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.