Skip to content

inconsistent outputs for pdf and png using AnchoredText #19676

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
jiadongdan opened this issue Mar 10, 2021 · 4 comments
Closed

inconsistent outputs for pdf and png using AnchoredText #19676

jiadongdan opened this issue Mar 10, 2021 · 4 comments

Comments

@jiadongdan
Copy link

Bug report

Bug summary

Using savefig to pdf and png, outputs are different.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import AnchoredText

fig, ax = plt.subplots(1, 1, figsize=(3.2, 3.2))

ax.imshow(np.random.rand(100 ,100), cmap='Blues', vmin=-0.1, vmax=0.8)
at = AnchoredText("texts",
                  prop=dict(size=12), frameon=True,
                  loc='upper left',borderpad=0.05,
                  )
#at.patch.set_boxstyle("round, pad=0.,rounding_size=0.2")
at.patch.set_alpha(0.5)
at.patch.set_edgecolor([1, 1, 1, 0.5])
at.patch.set_linewidth(1)
ax.add_artist(at)

fig.savefig('test.pdf', dpi=300)
fig.savefig('test.png', dpi=300, transparent=False) 

Actual outcome

pdf:

image

png:

image

PNG output has extra lines around the text, which is undesired.

Expected outcome

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.3.4
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7
  • Jupyter version (if applicable):
  • Other libraries:
@timhoffm
Copy link
Member

timhoffm commented Mar 10, 2021

I cannot reproduce this. The line is present in both cases, as one would expect because you set at.patch.set_linewidth(1).

PDF / png
grafik

Is this maybe an issue with your PDF viewer? - I've tested with okular.

@timhoffm timhoffm added the status: needs clarification Issues that need more information to resolve. label Mar 10, 2021
@jklymak
Copy link
Member

jklymak commented Mar 10, 2021

I get the layering of the frame in png, and PDF when viewed in Preview on a Mac.

Adobe Acrobat, however, does not composite the frame and its interior. This is easier to see if you use a wider frame and different color:

Adobe:

Adobe

Preview PDF:

Preview

PNG

PNG

I don't know that we can do anything here. Either argument can be claimed "correct" - we choose one thing in Agg, Preview and Okular the same thing, Adobe chooses something different.

@QuLogic
Copy link
Member

QuLogic commented Mar 11, 2021

That is likely #10035.

@timhoffm
Copy link
Member

I agree. I'm closing this as duplicate.

@timhoffm timhoffm added status: duplicate and removed status: needs clarification Issues that need more information to resolve. labels Mar 13, 2021
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