You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hatching in EPS figures doesn't show up in Preview on MacOS X with Matplotlib 2.0 #8289
Patches that have a hatch pattern in EPS plots don't show the hatch pattern when opened in Preview on MacOS X. This may be a Preview bug rather than a Matplotlib bug, but I wanted to check whether anything can be done on the Matplotlib side to avoid this (since the likelihood Apple will care about this issue is minimal). This was not a problem with Matplotlib 1.5, only with 2.0, so in that sense this is a regression.
Just to be sure: the hatches do actually exist in the EPS file (e.g. the issue is only with the preview)? I ran your MWE on Linux and Python 2 with Matplotlib 1.5.1 and 2.0: in Evince I can see hatches in both of them. However the hatches do not look exactly identical between both records, which I guess is due to #7421 (ping @QuLogic)
The changes in the individual commits of #7421 are fairly self-contained; it should be possible to try reverting them one at a time to see if they have any effect. At a guess, I'd say this commit and Preview has some trouble with the setpattern shortcut. You can revert the very last block in that patch to test out that theory.
Sorry, unexpected workload at day-job last night. So here are the differences that I can observe both in Evince and GS between Matplotlib 1.5.1 and 2.0:
The main one is that the hatches do not have a constant line width with 2.0.
Well, one difference is that the default figure size changed between 1.5
and 2.0. The spacing of the hatches is defined in points, so changing the
figure size will change that. I would suspect that some other changes to
the default style might explain some of the other 1.5/2.0 differences.
@WeatherGod I think the problem is not about the hatching style but more about how hatching is defined when saving in postscript and how it affects the rendering in Preview, Evince, GS, etc. as @QuLogic and @tacaswell have suggested. For example, when the hatches density is doubled ('//' instead of '/'), the not very aesthetic bold segments on some of the hatches are still there in EPS produced by 2.0, while the line width stays smooth and constant with 1.5(.1):
When I said diff I meant the text diff. I don't think the hatch changing width is real, that looks like issues with the renderer. Do they move around if you pan / zoom / resize the window?
The answer seems to be no with 1.5.1 (left panels) and yes with 2.0 (right panels):
The three level of zoom are 0.707, 1.000 and 2.000. With the EPS generated by Matplotlib 2.0, one can observe “glitches” for the two levels of zoom that are different from 1.
I agree that is is likely to be an issue with how the GS/Evince/Preview do the rendering.
@mryodo, I got the behaviour correct by inserting gsave and grestore in backend_ps.py. I don't known whether this will incur other problems, but at least you could give it a try.
I don't know how to present my modification here, so I just attach my git diff below. Hope it helps.
diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py
index 62edbb919..c8877e2ab 100644
--- a/lib/matplotlib/backends/backend_ps.py
+++ b/lib/matplotlib/backends/backend_ps.py
@@ -311,7 +311,9 @@ class RendererPS(RendererBase):
self._convert_path(Path.hatch(hatch), Affine2D().scale(sidelen),
simplify=False))
self._pswriter.write("""\
+ gsave
fill
+ grestore
stroke
} bind
>>
@mryodo, I got the behaviour correct by inserting gsave and grestore in backend_ps.py. I don't known whether this will incur other problems, but at least you could give it a try.
I don't know how to present my modification here, so I just attach my git diff below. Hope it helps.
diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py
index 62edbb919..c8877e2ab 100644
--- a/lib/matplotlib/backends/backend_ps.py
+++ b/lib/matplotlib/backends/backend_ps.py
@@ -311,7 +311,9 @@ class RendererPS(RendererBase):
self._convert_path(Path.hatch(hatch), Affine2D().scale(sidelen),
simplify=False))
self._pswriter.write("""\
+ gsave
fill
+ grestore
stroke
} bind
>>
Issue is still present in Matplotlib 3.1.1, but the posted fix worked like a charm! Thanks.
@mryodo, I got the behaviour correct by inserting gsave and grestore in backend_ps.py. I don't known whether this will incur other problems, but at least you could give it a try.
I don't know how to present my modification here, so I just attach my git diff below. Hope it helps.
diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py
index 62edbb919..c8877e2ab 100644
--- a/lib/matplotlib/backends/backend_ps.py
+++ b/lib/matplotlib/backends/backend_ps.py
@@ -311,7 +311,9 @@ class RendererPS(RendererBase):
self._convert_path(Path.hatch(hatch), Affine2D().scale(sidelen),
simplify=False))
self._pswriter.write("""\
+ gsave
fill
+ grestore
stroke
} bind
>>
Activity
afvincent commentedon Mar 14, 2017
Just to be sure: the hatches do actually exist in the EPS file (e.g. the issue is only with the preview)? I ran your MWE on Linux and Python 2 with Matplotlib 1.5.1 and 2.0: in Evince I can see hatches in both of them. However the hatches do not look exactly identical between both records, which I guess is due to #7421 (ping @QuLogic)
astrofrog commentedon Mar 14, 2017
@afvincent - yes, I think they do, I can see the hatches if I open the file with ghostscript
tacaswell commentedon Mar 14, 2017
what is the diff between the two files?
QuLogic commentedon Mar 14, 2017
The changes in the individual commits of #7421 are fairly self-contained; it should be possible to try reverting them one at a time to see if they have any effect. At a guess, I'd say this commit and Preview has some trouble with the
setpatternshortcut. You can revert the very last block in that patch to test out that theory.tacaswell commentedon Mar 14, 2017
https://github.com/matplotlib/matplotlib/pull/7421/files#diff-b465967f537465fec4960b152fa49cffR903 is likely the specific change at fault.
https://www.adobe.com/products/postscript/pdfs/PLRM.pdf has the documentation on this and
pg 264
afvincent commentedon Mar 15, 2017
Sorry, unexpected workload at day-job last night. So here are the differences that I can observe both in Evince and GS between Matplotlib 1.5.1 and 2.0:

The main one is that the hatches do not have a constant line width with 2.0.
WeatherGod commentedon Mar 15, 2017
afvincent commentedon Mar 16, 2017
@WeatherGod I think the problem is not about the hatching style but more about how hatching is defined when saving in postscript and how it affects the rendering in Preview, Evince, GS, etc. as @QuLogic and @tacaswell have suggested. For example, when the hatches density is doubled ('//' instead of '/'), the not very aesthetic bold segments on some of the hatches are still there in EPS produced by 2.0, while the line width stays smooth and constant with 1.5(.1):

tacaswell commentedon Mar 16, 2017
When I said diff I meant the text diff. I don't think the hatch changing width is real, that looks like issues with the renderer. Do they move around if you pan / zoom / resize the window?
afvincent commentedon Mar 16, 2017
The answer seems to be no with 1.5.1 (left panels) and yes with 2.0 (right panels):

The three level of zoom are 0.707, 1.000 and 2.000. With the EPS generated by Matplotlib 2.0, one can observe “glitches” for the two levels of zoom that are different from 1.
I agree that is is likely to be an issue with how the GS/Evince/Preview do the rendering.
I put the EPS files and a diff there
13 remaining items
mryodo commentedon Feb 7, 2019
Guys, has this issue been resolved? It seems like I'm having this problem on the latest module version. Or maybe any workaround?
mkvoya commentedon Feb 7, 2019
@mryodo, I got the behaviour correct by inserting
gsaveandgrestoreinbackend_ps.py. I don't known whether this will incur other problems, but at least you could give it a try.I don't know how to present my modification here, so I just attach my
git diffbelow. Hope it helps.anntzer commentedon Feb 7, 2019
https://stackoverflow.com/questions/6614207/how-to-export-non-blurry-eps-images for another case of Preview apparently not rendering postscript correctly.
mryodo commentedon Feb 7, 2019
@mksegv Thanx! Works perfectly!
czeni commentedon Aug 15, 2019
Issue is still present in Matplotlib 3.1.1, but the posted fix worked like a charm! Thanks.
jklymak commentedon Aug 15, 2019
Does anyone want to open a PR for that change?
QuLogic commentedon Jul 24, 2020
This should have been fixed by #15064.