-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Several hatching improvements #7421
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
Conversation
The hatch buffer was created at 72 pixels, with the assumption that that is the "unit square" (1in*1in). However, with default DPI increased to 100, that buffer is actually too small, causing hatching to be denser than it should be. On test images where the DPI was set really low, the hatching was less dense than it should be. Fixes matplotlib#4108.
Doesn't change anything; just makes it consistent with what it actually is. Also, remove comment about DPI-dependence, because hatching should not be DPI dependent.
Also, clean up some redundancies; 72 -> sidelen and the setpattern operator simplifies setting the pattern.
Agg uses top-left as origin, while PDF/PS use bottom-left. A vertical shift by the page height fixes that. See example in matplotlib#4108.
This matches behaviour with the Agg backend. Fixes matplotlib#3023. Fixes matplotlib#6228.
85b42b5
to
74e13fe
Compare
I've fixed the hatching origin in the PDF and PS backends, and also made a few other improvements in the PS backend. See the description for an updated explanation. Note, a lot of the PS and PDF backends don't really seem to be tested... Could add the test based on the related issues, but not sure where the best place is. |
Thanks for the patch! |
How can I set the hatch line color when using |
@jkokorian sorry meant #7976 |
thanks! |
Hi, Sorry I am a bit new to Python but I am having the same problems as in: #3023 I have re-installed Matplotlib and updated it but my hatches still do not show up when I save my plot as .pdf |
@andres0l1 Can you please open a new issue with a minimal example of what is not working for you? |
Sure I will! |
@@ -322,6 +322,7 @@ def create_hatch(self, hatch): | |||
self._convert_path(Path.hatch(hatch), Affine2D().scale(sidelen), | |||
simplify=False)) | |||
self._pswriter.write("""\ | |||
fill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone knows whether it is okay to write "fill" here? I deleted the "fill" and the hatch works on v3.0.2. The issue is described in #8289.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or shell we use the shfill
command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between fill
and shfill
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tacaswell sorry, I just skimmed the spec of EPS and found that shfill
(shading fill, which "paints the shape and color shading described by a shading dictionary, subject to the current clipping path") seems not related.
But I do have tried multiple manual fixes on the generated eps file and had the following findings:
- Simply removing the "fill" can solve the issue in Hatching in EPS figures doesn't show up in Preview on MacOS X with Matplotlib 2.0 #8289. But when we draw with "*", the stars are not filled with colors, which breaks Rasterizing patch changes filling of hatches in pdf backend #6228.
- Surrounding the
fill
withgsave
andgrestore
, also fixes Hatching in EPS figures doesn't show up in Preview on MacOS X with Matplotlib 2.0 #8289, but the result of Rasterizing patch changes filling of hatches in pdf backend #6228 is as follow.
I'm not familiar with the eps format, but hope the information is helpful.
This produces some more consistency for hatches across multiple backends.