Skip to content

[Bug]: hatch inconsistency between PDF and png #22862

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
caizixian opened this issue Apr 19, 2022 · 3 comments
Closed

[Bug]: hatch inconsistency between PDF and png #22862

caizixian opened this issue Apr 19, 2022 · 3 comments

Comments

@caizixian
Copy link

Bug summary

When drawing with hatches, dots show up in PDF as circles but they render fine as PNGs.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(6, 3))
ax.bar([1], height=4, hatch=".")
plt.savefig("demo.pdf")

fig, ax = plt.subplots(figsize=(6, 3))
ax.bar([1], height=4, hatch=".")
plt.savefig("demo.png", dpi=300)

Actual outcome

PDF
demo.pdf
PDF converted as png
demo

PNG
demo

Expected outcome

The PNG and the PDF should look the same.

Additional information

No response

Operating system

macOS 12.3.1

Matplotlib Version

3.4.3

Matplotlib Backend

module://matplotlib_inline.backend_inline (inside jupyter notebook), PDF backend when generating PDF

Python version

Python 3.8.9

Jupyter version

6.4.0

Installation

pip

@oscargus
Copy link
Member

oscargus commented Apr 19, 2022

This seems to be a problem for filled hatches. Same with '*'.

Maybe related to #3841 and #16052

@banarni
Copy link

banarni commented Jul 4, 2022

Just an additional observation for the backend-experts: A custom patch without facecolor is rendered correctly. Additionally, an edgecolor is only necessary for png export, not for pdf.

Code

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

fig, ax = plt.subplots(figsize=(6, 3))
bar = ax.bar([1], height=4, hatch=".", label="auto")
patch_custom_1 = Patch(label="custom - with fc", hatch=".", edgecolor="k")
patch_custom_2 = Patch(label="custom - without fc", hatch=".", edgecolor="k", facecolor="None")
patch_custom_3 = Patch(label="custom - without fc and ec", hatch=".", edgecolor="None", facecolor="None")

leg = plt.legend(handles=[bar, patch_custom_1, patch_custom_2, patch_custom_3], labelspacing=2, borderpad=1)
for patch in leg.get_patches():
    patch.set_height(20)
    patch.set_y(-7)

plt.xlim([0, 5])
plt.savefig("demo.pdf")

fig, ax = plt.subplots(figsize=(6, 3))
bar = ax.bar([1], height=4, hatch=".", label="auto")
patch_custom_1 = Patch(label="custom - with fc", hatch=".", edgecolor="k")
patch_custom_2 = Patch(label="custom - without fc", hatch=".", edgecolor="k", facecolor="None")
patch_custom_3 = Patch(label="custom - without fc and ec", hatch=".", edgecolor="None", facecolor="None")

leg = plt.legend(handles=[bar, patch_custom_1, patch_custom_2, patch_custom_3], labelspacing=2, borderpad=1)
for patch in leg.get_patches():
    patch.set_height(20)
    patch.set_y(-7)

plt.xlim([0, 5])
plt.savefig("demo.png", dpi=300)

Output

PDF (demo.pdf)
demo_pdf

PNG
demo

@QuLogic
Copy link
Member

QuLogic commented Jul 4, 2022

This is a duplicate of #10034.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants