Skip to content
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

[Bug]: .eps greyscale hatching of patches when lw=0 #22792

Closed
topper91 opened this issue Apr 6, 2022 · 3 comments · Fixed by #22794
Closed

[Bug]: .eps greyscale hatching of patches when lw=0 #22792

topper91 opened this issue Apr 6, 2022 · 3 comments · Fixed by #22794
Labels
backend: ps status: has patch patch suggested, PR still needed
Milestone

Comments

@topper91
Copy link

topper91 commented Apr 6, 2022

Bug summary

Export to .eps-format of patches that are filled with a colored hatch pattern appear in greyscale color when linewidth of the patch is set to zero.

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse

ax = plt.gca()
ax.add_patch(Ellipse((0, 0), 1, 1, hatch='/', facecolor='none', edgecolor='r', linewidth=0))

plt.savefig(r"E:\mwe.png")
plt.savefig(r"E:\mwe.eps")

plt.show()

Actual outcome

.eps-file converted to .png-format using GIMP 2.10.30

mwe_converted_from_eps

Expected outcome

.png-file exported by matplotlib

mwe

.eps-file exported by matplotlib with linewidth > 0 converted to .png-format using GIMP 2.10.30

mwe_2_converted_from_eps

Additional information

It happens when linewidth is set to zero.

I don't know if it worked in earlier versions.

I had a look on the eps-commands in the file. (I don't know anything about eps-format.) It is most likely due to certain eps-commands being removed when linewidth is set to zero, including a command for the line color.

Operating system

Windows 10

Matplotlib Version

3.5.1

Matplotlib Backend

TkAgg

Python version

3.9.10

Jupyter version

n/a

Installation

pip

@jklymak
Copy link
Member

jklymak commented Apr 6, 2022

Thanks for the helpful bug summary and looking into the possible cause (which sounds reasonable). Not sure who will step up to fix this, but it does seem like somehow the colours are not getting set. Perhaps see if pdf works?

@topper91
Copy link
Author

topper91 commented Apr 6, 2022

thx for the quick response. pdf-export works just fine.

@oscargus
Copy link
Member

oscargus commented Apr 6, 2022

A quick diff between the mwe here and one with setting linewidth to 0.1.

(base) lnx00073 [~]> diff mwe.eps mwe2.eps 
2c2
< %%Title: mwe.eps
---
> %%Title: mwe2.eps
4c4
< %%CreationDate: Wed Apr  6 16:08:50 2022
---
> %%CreationDate: Wed Apr  6 16:09:28 2022
242a243,247
> 0.100 setlinewidth
> 0 setlinejoin
> 0 setlinecap
> [] 0 setdash
> 1.000 0.000 0.000 setrgbcolor
291a297
> stroke
295,296d300
< 0 setlinecap
< [] 0 setdash

I'd say that it is these lines that are not executing:

if mightstroke:
self.set_linewidth(gc.get_linewidth())
self.set_linejoin(gc.get_joinstyle())
self.set_linecap(gc.get_capstyle())
self.set_linedash(*gc.get_dashes())
self.set_color(*gc.get_rgb()[:3])
as mightstroke is False (as linewidth is 0).

Moving the color-setting out of the if-clause seems to solve this problem, but I am not sure if it causes other issues.

Edit:

I don't know if it worked in earlier versions.

That code has been around for 14 years, so it is not a recent regression. Hence, this should probably go into 3.6.

@oscargus oscargus added the status: has patch patch suggested, PR still needed label Apr 6, 2022
@oscargus oscargus added this to the v3.6.0 milestone Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: ps status: has patch patch suggested, PR still needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants