Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 16 commits intomatplotlib:mainfromImpaler343:collections-hatchcolor
Mar 31, 2025
Merged
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
d7da1fc
add hatchcolors param for collections
r3ksteJan 3, 2025
2fd17a0
minor fixes
r3ksteJan 3, 2025
f5978ce
added gallery example
r3ksteJan 8, 2025
5377127
documented hatchcolor parameter for collections in next whats new entry
r3ksteJan 20, 2025
6f18c49
update whats new for hatchcolor in collections
r3ksteJan 27, 2025
8a7cd65
update contourf hatch test with cmap.with_alpha()
r3ksteJan 29, 2025
e3b03fc
grammar nits
Impaler343Feb 5, 2025
7668535
enhanced tests and made hatchcolors param required in _iter_collection()
r3ksteFeb 5, 2025
9d0ec23
smoke test for hatchcolors coercion
r3ksteFeb 8, 2025
7e46707
pass hatchcolor arg only if it is supported by the renderer. and made…
r3ksteFeb 16, 2025
c5e9583
Fix hatchcolors argument support in third-party backends
r3ksteFeb 22, 2025
d2b6268
Add note about provisional API for draw_path_collection()
r3ksteFeb 23, 2025
fee895b
Refactor draw_path_collection to make `hatchcolors` a keyword-only ar…
r3ksteMar 16, 2025
b9ac0fb
Made suggested changes
r3ksteMar 22, 2025
2e4784b
added test and improve comments for third party backend support of ha…
r3ksteMar 28, 2025
3b43bc6
skip unnecessary path iteration when hatchcolors is not passed/needed
r3ksteMar 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Fix hatchcolors argument support in third-party backends
  • Loading branch information
@r3kste
r3kste committedFeb 22, 2025
commitc5e9583a5e78bb1b1af1fefffc33c13a4831aa59
50 changes: 36 additions & 14 deletionslib/matplotlib/collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -431,29 +431,51 @@
self._antialiaseds, self._urls,
"screen", self.get_hatchcolor()
)
except TypeError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems to me like a pretty brittle way of checking ifdraw_path_collection has ahatchcolors argument (ie. it could fail for other cases than justhatchcolors isn't present). Instead, could youinspect the signature ofrenderer.draw_path_collection to definitively decide whether to pass hatchcolors or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As explained by anntzer in thiscomment,

matplotlib has not required the signature of third-party draw_path_collection implementations to be introspectable e.g. with inspect.signature

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It's worth explicitly documenting this in the comment, see suggestion above.

r3kste reacted with thumbs up emoji
hatchcolors_arg_supported = False

Check warning on line 435 in lib/matplotlib/collections.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/collections.py#L434-L435

Added lines #L434 - L435 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

codecov is saying that these lines aren't covered (and several other lines in this file). Could you add some tests for these lines? They don't have to be figure tests, they can just test that the code works without erroring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

These lines are run only in the case of a third-party backend. However, I am not sure how to test this within the current testing framework of matplotlib, without a third-party backend.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You can make a mock third party backend to call the function - there are some examples of other mocks in the tests

r3kste reacted with thumbs up emoji

if self._gapcolor is not None:
# First draw paths within the gaps.
ipaths, ilinestyles = self._get_inverse_paths_linestyles()
args = [gc, transform.frozen(), ipaths, self.get_transforms(),
offsets, offset_trf, [mcolors.to_rgba("none")],
self._gapcolor, self._linewidths, ilinestyles,
self._antialiaseds, self._urls, "screen"]
if hatchcolors_arg_supported:
args.append(self.get_hatchcolor())
args = [offsets, offset_trf, [mcolors.to_rgba("none")], self._gapcolor,
self._linewidths, ilinestyles, self._antialiaseds, self._urls,
"screen", self.get_hatchcolor()]

renderer.draw_path_collection(*args)
if hatchcolors_arg_supported:
renderer.draw_path_collection(gc, transform.frozen(), ipaths,
self.get_transforms(), *args)
else:
# If the renderer does not support the hatchcolors argument,
# iterate over the paths and draw them one by one.
path_ids = renderer._iter_collection_raw_paths(

Check warning on line 450 in lib/matplotlib/collections.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/collections.py#L450

Added line #L450 was not covered by tests
transform.frozen(), ipaths, self.get_transforms())
for xo, yo, path_id, gc0, rgbFace in renderer._iter_collection(
gc, list(path_ids), *args
):
path, transform = path_id

Check warning on line 455 in lib/matplotlib/collections.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/collections.py#L455

Added line #L455 was not covered by tests
if xo != 0 or yo != 0:
transform = transform.frozen()
transform.translate(xo, yo)
renderer.draw_path(gc0, path, transform, rgbFace)

Check warning on line 459 in lib/matplotlib/collections.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/collections.py#L457-L459

Added lines #L457 - L459 were not covered by tests

args = [offsets, offset_trf, self.get_facecolor(), self.get_edgecolor(),
self._linewidths, self._linestyles, self._antialiaseds, self._urls,
"screen", self.get_hatchcolor()]

args = [gc, transform.frozen(), paths, self.get_transforms(),
offsets, offset_trf, self.get_facecolor(),
self.get_edgecolor(), self._linewidths, self._linestyles,
self._antialiaseds, self._urls, "screen"]
if hatchcolors_arg_supported:
args.append(self.get_hatchcolor())

renderer.draw_path_collection(*args)
renderer.draw_path_collection(gc, transform.frozen(), paths,
self.get_transforms(), *args)
else:
path_ids = renderer._iter_collection_raw_paths(

Check warning on line 469 in lib/matplotlib/collections.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/collections.py#L469

Added line #L469 was not covered by tests
transform.frozen(), paths, self.get_transforms())
for xo, yo, path_id, gc0, rgbFace in renderer._iter_collection(
gc, list(path_ids), *args
):
path, transform = path_id

Check warning on line 474 in lib/matplotlib/collections.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/collections.py#L474

Added line #L474 was not covered by tests
if xo != 0 or yo != 0:
transform = transform.frozen()
transform.translate(xo, yo)
renderer.draw_path(gc0, path, transform, rgbFace)

Check warning on line 478 in lib/matplotlib/collections.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/collections.py#L476-L478

Added lines #L476 - L478 were not covered by tests

gc.restore()
renderer.close_group(self.__class__.__name__)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp