Plots.jl
Plots.jl copied to clipboard
[BUG] Issues with saving plot as pdf
Details
I was trying to save plots generated using gr() backend in pdf format and this messes up the negative values along x & y-axes. This doesn’t seem to happen when the figure is saved as png though. I isolated this issue to the plot() argument, fontfamily = font(48, "helvetica")
. I am attaching the MWE I used below
using Plots
gr()
plot(-5:5, -5:5, title = "title", xlabel = "x", ylabel = "y", label = "1", fontfamily = font(48, "helvetica"))
savefig("./test.pdf")
savefig("./test.png")
-
Figure saved as png
-
Figure saved as pdf test.pdf
Backends
This bug occurs on ( insert x
below )
Backend | yes | no | untested |
---|---|---|---|
gr (default) | x | ||
pyplot | x | ||
plotly | x | ||
plotlyjs | x | ||
pgfplotsx | x | ||
inspectdr | x |
Versions
Plots.jl version: Plots v1.6.6
Backend version (]st -m
): GR v0.52.0
Output of versioninfo()
: Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin18.7.0)
CPU: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, broadwell)
Environment:
JULIA_NUM_THREADS = 2
It's possible that this is caused by an issue the underlying GR backend's pdf driver: https://gr-framework.org/encoding.html
I just wanted to point out that I am having the same issue with the Times Roman font. Minimum working example below:
using Plots
gr()
x = -10:10
p = plot(x,x, ytickfont = Plots.font("times"))
savefig(p,"asPNG.png")
savefig(p,"asPDF.pdf")
The error does not occur with certain other fonts, e.g. Computer Modern.
I find this issue still holds for the "-" sign.
It holds for many fonts, except Computer Modern
, sans-serif
, and serif-roman
.
The pdf savefig()
also exports/renders fonts in a strange scale/shape, such as Bookman or Palatino does not even look like Palatino.
Is there a way to setup the encoding or how the pdf render works for Plots ?
This is a code I run on MacOS, but it holds years now.
using Plots
# _ Fonts
ftb = ["times", "Helvetica", "courier", "Computer Modern", "bookman", "newcenturyschlbk", "avantgarde", "Palatino", "serif-roman", "sans-serif"]
# _ different backends, tested only gr() in Plots
backend_x = "plots_gr"
gr()
x = [randn(50) for i in 1:3]
xt = LinRange(-2,2,50)
plots_array = []
for (i, fi) in enumerate(ftb)
# label tests - sign in other texts as labels or legend
p1 = scatter(xt, x, label=["x1 (-1,1)" "x2 +4" "x3 -98"], title="font $fi", framestyle=:box, fontfamily=fi, size=(400,400), ylabel="-3 -text", xlabel="-3 -text")
push!(plots_array, p1)
display(p1)
savefig(p1, "plots/problem/plot_b_$(backend_x)_f_$fi.pdf")
end
[display(p) for p in plots_array]
It does not seem to be resolved yet. I am using fontfamily="Palatino"
and I am getting ?
in place of -
when I am saving plots as PDF. Has anyone found a solution or a workaround?
Thanks!
I'm getting the same error. I'm also on Mac and trying to save a pdf of the plot with Palatino as the fontface. It would be great if anyone has a solution.
Same error here, font is Helvetica.
When on macOS, “Arial”
works ok.