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] heatmap blurry when saved as pdf (macOS) #4840

Open
mauricelanghinrichs opened this issue Oct 30, 2023 · 7 comments
Open

[BUG] heatmap blurry when saved as pdf (macOS) #4840

mauricelanghinrichs opened this issue Oct 30, 2023 · 7 comments

Comments

@mauricelanghinrichs
Copy link

mauricelanghinrichs commented Oct 30, 2023

Heatmaps created by Plots.jl are blurred when saved as pdf on my system (recent Julia, Plots, GR versions; macOS). They look fine in VScode and also when saved as png (see MWE and images below).

I think something is wrong with vector graphics interpolation and subsequent display under macOS. I can do the same heatmap with CairoMakie.jl and it is saved and displayed correctly. I would like to stay with Plots.jl, so any help/fix really appreciated.

MWE

using Plots
using Random

Random.seed!(20231030)

A = rand(5,5)

heatmap(A, clims=(0,1))

cd(expanduser("~/")*"Desktop")
pwd()

savefig("./heatmap_test.pdf")
savefig("./heatmap_test.png")

Screenshot of the saved pdf (what I "see" on my system):
Screenshot 2023-10-30 at 14 20 22

the pdf itself
heatmap_test.pdf

the png
heatmap_test

Backends

This bug occurs on

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots v1.39.0
GR v0.72.10

Julia Version 1.9.1
Commit 147bdf428cd (2023-06-07 08:27 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin22.4.0)
CPU: 8 × Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
Threads: 4 on 8 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS = 4
DYLD_FALLBACK_LIBRARY_PATH =

@jheinen
Copy link
Member

jheinen commented Nov 3, 2023

If you view the result with Acrobat (Reader), everything looks fine. The interpolation is therefore only applied during rendering in the Preview app.

@mauricelanghinrichs
Copy link
Author

Thanks for your help!
Yes, I noticed that also with Affinity Designer. Still, there is no option to my knowledge to change Preview's interpolation setting, and heatmaps produced with CairoMakie.jl or python will look fine with Preview. So there must be something that can be done in Plots.jl or its backends?

Also related, the heatmaps will look blurred in presentations with Powerpoint or Apple's Keynote (at least on my system), as they probably use a similar or identical rendering as in Previews. Also one cannot use these heatmaps in publications as they may look blurred to any person opening them on macOS. I think this is quite a limitation?

@jheinen
Copy link
Member

jheinen commented Nov 3, 2023

... and heatmaps produced with CairoMakie.jl or python will look fine with Preview. So there must be something that can be done in Plots.jl or its backends?

That's because in CairoMakie or Python they are probably rendered using filled rectangles, which would be inefficient for huge heatmaps. I could implement a workaround and optionally change the rendering method in GR based on an environment variable.

However, the problem only occurs in Apple's Preview and has existed for years. Other viewers (Acrobat, Skim, ...) render the images as specified in the PDF.

@mauricelanghinrichs
Copy link
Author

Ok I see, thank you for the explanation! Quite annoying though that Preview uses such a default.. but maybe they have their reasons too.
Personally I would love to have any kind of optional keyword in heatmap / some way to make (small) heatmaps work with preview would be great!

@jheinen
Copy link
Member

jheinen commented Nov 3, 2023

@BeastyBlacksmith : So should we use an inefficient and incorrect representation for heatmaps simply because one(!) system/viewer does not render the resulting PDF correctly? In addition, when rendering with filled rectangles, anti-aliasing effects occur that you actually do not want.

BTW: I have added a workaround for Apple's Preview (in the GR development version) which can be activated using the GKS_PDF_PREVIEW_FIX environment variable. But I am somehow reluctant to make this the default.

@BeastyBlacksmith
Copy link
Member

So should we use an inefficient and incorrect representation for heatmaps simply because one(!) system/viewer does not render the resulting PDF correctly?

I don't think so. Having a documented workaround for people who do care would be welcome.

@jheinen
Copy link
Member

jheinen commented Nov 3, 2023

I was just wondering because it is labeled as a bug in GR.

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

3 participants