# GADFLY Font Change Not Saving

**URL:** <https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044>\
**Category:** Visualization\
**Tags:** question, plotting, gadfly\
**Created:** [February 4, 2023, 12:45pm UTC](https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044 "2023-02-04T12:45:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisVL1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisvl1/32/45240_2.png) [@ChrisVL1](https://discourse.julialang.org/u/ChrisVL1)\
**Post date:** [February 4, 2023, 12:45pm UTC](https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044/1 "2023-02-04T12:45:20Z")

</div>

When changing the label font and saving as a PDF, the saved pdf does not display the changed font style. Here’s an example:

```julia
xs = convert(Vector{Float64}, tsteps)  

layer2 = layer(x=xs1, y=Euler_Maruyama1,Geom.line,Theme(line_width = 1pt,default_color=colorant"#1E90FF"))
layer4 = layer(x=xs1, y=Milstein1,Geom.point, shape=[Gadfly.Shape.xcross],Theme(line_width = 1pt,default_color=colorant"#006400"))
layer3 = layer(x=xs1, y=GBM1, Geom.line,Theme(line_width = 1pt,default_color=colorant"#FF0000"))
p1 = Gadfly.plot(layer4,layer3,layer2, Guide.xticks(ticks = [0 0.25 0.5 0.75 1]),Theme(grid_line_width=0mm,panel_stroke=color("black"),major_label_font="times-new-roman",minor_label_font="times-new-roman",key_label_font="times-new-roman",key_label_font_size=6pt,major_label_font_size=8pt),Guide.yticks(ticks = [92 97 102 107 112]),Guide.xlabel("Time"), Guide.ylabel("Stock Price"),Guide.manual_color_key("", ["Analytical Solution","Euler-Maruyama Method","Milstein Method"],["#FF0000","#1E90FF","#006400"],pos=[0.05w,-0.45h],shape=[Gadfly.Shape.hline,Gadfly.Shape.hline,Gadfly.Shape.xcross]),Coord.cartesian(xmin=0, xmax=1, ymin=92, ymax=112))

layer5 = layer(x=xs, y=Milstein_Diff, Geom.line,Theme(line_width = 1pt,default_color=colorant"#006400"))
layer1 = layer(x=xs, y=Euler_Maruyama_Diff, Geom.line,Theme(line_width = 1pt,default_color=colorant"#1E90FF"))
p2 = Gadfly.plot(layer1,layer5,Guide.yticks(ticks = [-4.0 -3.0 -2.0 -1.0 0]), Guide.xticks(ticks = [0 0.25 0.5 0.75 1]),Theme(major_label_font="times-new-roman",minor_label_font="times-new-roman",key_label_font="times-new-roman",grid_line_width=0mm,panel_stroke=color("black"),key_label_font_size=6pt,major_label_font_size=8pt),Guide.xlabel("Time"),Guide.ylabel("log₁₀ Absolute Error"),Guide.manual_color_key("", ["Euler-Maruyama Error","Milstein Error"],["#1E90FF","#006400"],pos=[0.05w,-0.45h],shape=[Gadfly.Shape.hline,Gadfly.Shape.hline]))

plt = hstack(p1,p2)

```

This is how it is displayed with the changed font style in the notebook (which I want):

 ![Screenshot 2023-02-04 at 14.43.53](https://global.discourse-cdn.com/julialang/original/3X/b/b/bbef9edba836fa891c2400bd91128e33918777e6.png)

This is how it is saved, as you can see the font has not been changed:

 ![Screenshot 2023-02-04 at 14.44.22](https://global.discourse-cdn.com/julialang/original/3X/d/c/dc6134fb767b4b129dc5fd5e92e2b6de99364730.png)

How do I save it with the changed font?

---

<div class="post-metadata">

**Author:** ![ChrisVL1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisvl1/32/45240_2.png) [@ChrisVL1](https://discourse.julialang.org/u/ChrisVL1)\
**Post date:** [February 4, 2023, 5:25pm UTC](https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044/2 "2023-02-04T17:25:57Z")

</div>

@Mattriks have you come across this problem? A similar problem is unanswered from a few years ago [draw - How to save plots with the correct theme (local font) using Gadfly in Julia language? - Stack Overflow](https://stackoverflow.com/questions/38686788/how-to-save-plots-with-the-correct-theme-local-font-using-gadfly-in-julia-lang) .

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [February 5, 2023, 6:48am UTC](https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044/3 "2023-02-05T06:48:46Z")

</div>

On linux, all linux fonts work for me, both in Jupyter and saving Gadfly plots to pdf. The font in your example is a MS font (does it work if you change the font to “Times” or “TimesNewRoman”?). Gadfly is a program that “makes plots”, but the graphics output is handled by other packages (in the case of PDF, by Cairo.jl, check there). I also found the issue mentioned at Gadfly.jl: [draw function removes specified font · Issue #621 · GiovineItalia/Gadfly.jl · GitHub](https://github.com/GiovineItalia/Gadfly.jl/issues/621).

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [February 5, 2023, 5:04pm UTC](https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044/4 "2023-02-05T17:04:53Z")

</div>

Hi @ChrisVL1 Sorry, I couldn’t run your code - it’s sometimes useful to provide a tiny example that shows the problem. Also, with anything to do with these pesky fonts, it might be important to know which OS you’re running, and whether you’ve installed any.

Anyway, if you’re not too fussy about the exact font, you could try specifying the ‘font name’ as `"serif"` - if you’re lucky Cairo and Fontconfig will find a suitable Times font that matches. In fact on my Mac it finds the Linotype version of Times Roman rather than the Monotype Times New Roman. I don’t know why…

It’s also possible to specify and get `"Palatino"` (or `"Optima"` or `"Marker Felt"` (because they’re Mac system fonts and always available). I’ve not been able to obtain “Times New Roman” in a PDF from Gadfly.jl (unless I take steps to install and activate it first). 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![ChrisVL1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisvl1/32/45240_2.png) [@ChrisVL1](https://discourse.julialang.org/u/ChrisVL1)\
**Post date:** [February 6, 2023, 12:48am UTC](https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044/5 "2023-02-06T00:48:43Z")

</div>

> [@Mattriks](#):
>
> “Times” or “TimesNewRoman”

Hi @cormullion, @Mattriks response of using the exact font name (i.e. “Times” or “TimesNewRoman”) solved the issue, but thanks for the recommendations.

While you are here, what is the best way to save plots? The font comes out strange when saving as a PDF, specifically the spacing between letters.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [February 6, 2023, 2:25am UTC](https://discourse.julialang.org/t/gadfly-font-change-not-saving/94044/6 "2023-02-06T02:25:42Z")

</div>

Not sure about “spacing between letters”, but does your issue match anything in [Overlapping labels for the top and bottom legend when drawing to PNG/PDF · Issue #688 · GiovineItalia/Gadfly.jl · GitHub](https://github.com/GiovineItalia/Gadfly.jl/issues/688) or [https://github.com/GiovineItalia/Gadfly.jl/issues/1587](https://github.com/GiovineItalia/Gadfly.jl/issues/1587)?

A mwe to try could be something like:

```julia
fnt1 = "TimesNewRoman"
p = plot(Geom.blank,
 Theme(grid_line_width=0mm, panel_stroke="black", major_label_font=fnt1, minor_label_font=fnt1, major_label_font_size=8pt,
        key_label_font=fnt1, key_label_font_size=6pt),
  Guide.xlabel("Time"), Guide.ylabel("Stock Price"),
  Guide.manual_color_key("", ["Analytical Solution", "Euler-Maruyama Method", "Milstein Method"],
  ["#FF0000","#1E90FF","#006400"], pos=[0.05w,-0.40h],
 shape=[Gadfly.Shape.hline, Gadfly.Shape.hline, Gadfly.Shape.xcross])
)

draw(PDF(string("font_", fnt1,".pdf"), 3.3inch, 3.3inch), p)

```
