-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Hatch pattern changes with dpi #4108
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
Comments
Is this something that can even be ensured? The rasterized hatch is going to be fixed, where as the vector hatch is controlled by the viewer? |
It might be possible to force the rasterisation of the legend patch as well. Not a solution, but at least legend and graph would match. |
That makes sense. |
Stumbled over this myself just now. We'll have to rasterize (to preserve the look of the plot for a publication, not making it viewer-dependent), but when rasterizing, the dpi influcence the hatch size/spacing. This, in the end, prevents users from having a high-res but widely spaced '/' hatch for instance. Currently, the higher your dpi is, the more '/' lines you get (closer together). |
I have been looking at the source code, but from that it is not apparent to me what the intent is in the first place. hatches have a 'density', which is 'the number of lines in a unit square' (hatch.py). I didn't find any definition for 'unit square' though - and the question is: does it's size depend on the resolution? Also, this does not only affect the AGG or pdf backend. I see the same for, e.g., the eps backend. Also there, the look of the actual hatch pattern depends on the chosen dpi. This is not what I would expect, or want. |
Sorry for spamming so much. I couldn't let go of the source code, and it looks to me now as a "unit square" is meant to be a 1inx1in square (from #4122). Given this, the current behavior would indeed be a bug. Looking at both the pdf and ps backends, I see a fixed 'resolution' of 72 when handling hatches, given as the length of the sides of the 'unit square' (e.g. line 1164ff in backends/backend_pdf.py). Could it be that the actual used dpi should be used here? On the other hand, that file also contains a comment: # TODO: We could make this dpi-dependent, but that would be an API change. I'll now drop this and try to get a workaround working, but it would be nice to have this working in the future obviously. |
@knarrff Were you able to find a workaround for this? |
For that one publication we just adapted the density by hand. I didn't bother finding a more general work-around. It would still be nice to have it fixed. It would be nice to get a comment from one of the knowledgeable developers as to which direction they would like to see for a fix - then it might make sense to look into it again. |
@knarrff Can you please tell me how did you change the density. |
This appears rather straightforward to fix; @tacaswell I wonder if we should target 2.0 for this? |
@QuLogic, give it a shot. It's worth trying to get it in. |
In other words, if it's ready in time, that's a bonus; otherwise it will go in the next release. |
I think all our tests were rendered at the wrong DPI (probably okay before it was changed), so it's probably best to get a change like this in with 2.0. |
To answer this question, I don't believe so. The 72 is from the definition of PDF files, and not related to the dpi of the figure. The dpi only applies to raster images, such as the ones with |
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.
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.
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.
Closed in #7421 |
Hi, I currently use matplotlib a lot - thanks for your nice work! I noticed that the hatch patterns change with the dpi settings. This is not a big problem as long as you raster the whole plot. However, if you only raster parts of it, you will find that the legend not longer matches the pattern in the bars and that there is a gap at the bottom of the bars.
And this is how

dpi050.pdf
looks:The text was updated successfully, but these errors were encountered: