Plots.jl
Plots.jl copied to clipboard
White lines in saved pdf-file
Hi,
thank you for developing this great tool!
I am using Plots with the pyplot backend. When I save a Plot with heatmaps as subplots, the saved figure shows white lines in the pdf-viewer. This is a native pyplot problem, as it is discussed here. I was facing the same problem when using pyplot's pcolor in Python. The workaround there is something like setting rasterized = true
. Is there a workaround in Plots.jl?
Hi, thanks a lot for reporting!
Unfortunately I cannot reproduce this, which makes it hard to fix or check if it is fixed.
Since you already proposed a solution it would be great if you could check locally if adding rasterized = true,
somewhere here https://github.com/JuliaPlots/Plots.jl/blob/master/src/backends/pyplot.jl#L767-L774 fixes the issue for you. If it does, a PR is very welcome!
I have the same problem. @PhilippAumann did you find a solution?
@SebastianAment could you provide a MWE to reproduce the issue?
@daschw the issue appears to be with savefig
and the PDF format.
using Plots
pyplot()
n = 64
z = ones(n, n)
f = heatmap(z)
gui() # this shows the heatmap without the lines
savefig(f, "test.pdf") # the pdf has white lines between cells
I tested several output formats on two machines, one on Linux and one on MacOS. PNG works as expected, but PDF and others like PS include lines*. I have attached the images which result from the example on my machine:
*PS only includes horizontal lines, while the PDF has both horizontal and vertical lines.
On Windows with pyplot()
and heatmap, I get the same problem with savefig
in pdf (and not in png).
Does someone have a solution for this issue?
I have the same issue, in Linux and Windows.
According to the documentation of matplotlib the rasterization can be controlled by the zorder
by setting set_rasterization_zorder(...)
on the axis. In Julia:
const plt = import PyPlot
plt.pcolormesh(rand(10,10); zorder=-1)
plt.title("title")
plt.gca()."set_rasterization_zorder"(0)
plt.savefig("pyplot.pdf")
correctly rasterizes the heatmap but not the ticks, labels, title etc pyplot.pdf
The same can be achieved by
plt.pcolormesh(rand(10,10); rasterized=true)
plt.title("title")
plt.savefig("pyplot2.pdf")
I do not know how to implement in Plots.jl
. I guess the latter approach is the easier one to implement. To former has the advantage that a multiple parts of a plot can be rasterized into one image, see this stackexchange post. Maybe @daschw or @BeastyBlacksmith can help?
CC: @isentropic
It would be no problem to add rasterized = True
extra kw (https://docs.juliaplots.org/stable/backends/#Fine-tuning-3) flag if that would solve it. I personally encountered this issue before but its hard to tackle as the rendering is completely handled by matplotlib. Would this solve the issue at least partially?
Having this flag True
by default might break some plots I'm afraid (esp. for people who render pdfs for papers). So we can make it optional by default
@isentropic How does this work?
heatmap(rand(10,10); extra_kwargs=Dict(:subplot=>Dict("rasterized"=>true)))
does not seem to have any effect in vscode plotting pane or in saved pdf.
Julia-1.9
Plots v1.39.0
PythonPlot v1.0.2
Here is an example output in the vscode plotting pane:
Setting fmt=:png
does not have an effect on the output figure in the vscode plotting pane nor on the saved pdf file.
It has an effect of the output in Pluto.jl
:
This has not been implemented yet. I wanted to know if this is any useful