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] Issues with saving plot as pdf #3004

Open
bhache opened this issue Sep 24, 2020 · 7 comments
Open

[BUG] Issues with saving plot as pdf #3004

bhache opened this issue Sep 24, 2020 · 7 comments

Comments

@bhache
Copy link

bhache commented Sep 24, 2020

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")
  1. Figure saved as png
    test

  2. 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

@dapplegate
Copy link

It's possible that this is caused by an issue the underlying GR backend's pdf driver: https://gr-framework.org/encoding.html

@nfernandez-arias
Copy link

nfernandez-arias commented Aug 27, 2021

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.

@t-bltg t-bltg added the fonts label Nov 27, 2022
@luboshanus
Copy link

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]

@moshialam
Copy link

moshialam commented Aug 25, 2023

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!

@mauricioabur
Copy link

mauricioabur commented Sep 3, 2023

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.

@marvinlenk
Copy link

Same error here, font is Helvetica.

@luboshanus
Copy link

When on macOS, “Arial” works ok.

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

9 participants