Plots.jl
Plots.jl copied to clipboard
[BUG] heatmap blurry when saved as pdf (macOS)
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):
the pdf itself
the png
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 =
If you view the result with Acrobat (Reader), everything looks fine. The interpolation is therefore only applied during rendering in the Preview app.
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?
... and heatmaps produced with
CairoMakie.jlor python will look fine with Preview. So there must be something that can be done inPlots.jlor 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.
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!
@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.
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.
I was just wondering because it is labeled as a bug in GR.