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

Fix Hatch Color #27949

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

Closed
Impaler343 wants to merge 1 commit into matplotlib:main from Impaler343:hatch-patch2
Closed

Fix Hatch Color #27949

Impaler343 wants to merge 1 commit into matplotlib:main from Impaler343:hatch-patch2

Conversation

Copy link
Contributor

@Impaler343 Impaler343 commented Mar 19, 2024

PR summary

Closes #8865
Simple fix by checking if face-color is the same as edge-color for a patch, If yes, do not update hatch-color

Gives the needed output:

image

PR checklist

Copy link
Contributor Author

I'm not sure about how to solve these code-cov failing tests, can someone help me out?

self.set_facecolor(facecolor)
self.set_edgecolor(edgecolor)
Copy link
Contributor

@davidlowryduda davidlowryduda Mar 20, 2024

Choose a reason for hiding this comment

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

Does the order of these lines matter?

Copy link
Contributor Author

@Impaler343 Impaler343 Mar 20, 2024

Choose a reason for hiding this comment

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

Yes, the facecolor attribute must be defined first to use it later in the _set_edgecolor method

davidlowryduda reacted with thumbs up emoji
Copy link
Contributor Author

Could somebody take a look at this patch?

Copy link
Member

rcomer commented Apr 1, 2024

Please add a test to verify the new behaviour. Otherwise future changes might inadvertently break it again.
https://matplotlib.org/devdocs/devel/testing.html

Impaler343 reacted with thumbs up emoji

Copy link
Member

timhoffm commented Apr 1, 2024
edited
Loading

Updating the hatch color depending on the face color does not feel right. While it may result in hatching for the given example, it may result in strange order dependent behavior. Say, your patch face Color is white and you want to change that to grey with white hatching. With this PR, it only works for

patch.set_facecolor(„grey")
patch.set_edgecolor(„white")

But not if you change the order of both lines.

I’m on mobile, so cannot dig fully into the context, but I have the impression that the underlying problem of the original issue may be that hatch color and face color are the same so that the hatch is drawn but not visible. Can you confirm this? If that is the case, other fixes (or maybe no fix at all) are needed - which depends on the context.

Copy link
Contributor Author

Updating the hatch color depending on the face color does not feel right. While it may result in hatching for the given example, it may result in strange order dependent behavior. Say, your patch face Color is white and you want to change that to grey with white hatching. With this PR, it only works for

patch.set_facecolor(„grey")
patch.set_edgecolor(„white")

But not if you change the order of both lines.

I’m on mobile, so cannot dig fully into the context, but I have the impression that the underlying problem of the original issue may be that hatch color and face color are the same so that the hatch is drawn but not visible. Can you confirm this? If that is the case, other fixes (or maybe no fix at all) are needed - which depends on the context.

Yes you are right, the hatch color is set based on the edge color which is set to (0,0,0,0). Hence, the patch. I probably need to default to rcParams if the face color and edge colors match?

Copy link
Member

timhoffm commented Apr 1, 2024

Ok, so the issue here is that the default edge color for the figure patch is such that the hatching is invisible. I'd then claim that everything works as intended and we should close both this PR and the issue. The resolution to the issue would be on the user side to set an edge color when they want hatching. Ping @anntzer for confirmation.

Impaler343 reacted with thumbs up emoji

@timhoffm timhoffm added status: needs comment/discussion needs consensus on next step and removed status: needs tests labels Apr 1, 2024
Copy link
Contributor

anntzer commented Apr 1, 2024

Yes, looking at it again the issue was just invalid and arising because the patch edgecolor also defaults to white. Thanks for resurrecting the discussion, though!

Impaler343 reacted with thumbs up emoji

Copy link
Contributor Author

Impaler343 commented Apr 1, 2024
edited
Loading

The resolution to the issue would be on the user side to set an edge color when they want hatching

Should we add this to the docs then? Recommending to always set edge color when setting hatches, as it is confusing to not see a hatch when it is specified explicitly

Copy link
Member

timhoffm commented Apr 1, 2024

This applies only to the figure patch, because that has different defaults. We don’t have specific documentation for the figure patch and IMHO it’s really rare to hatch the figure. I wouldn’t clutter the regular docs with that.

Impaler343 reacted with thumbs up emoji

@Impaler343 Impaler343 deleted the hatch-patch2 branch April 12, 2024 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
1 more reviewer

@davidlowryduda davidlowryduda davidlowryduda approved these changes

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
status: needs comment/discussion needs consensus on next step
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Figure patch does not support hatching

AltStyle によって変換されたページ (->オリジナル) /