2

I need to modify which font is used for titles, labels, and annotations in a Julia plot. It needs to be Arial Bold or something reasonably similar. (Not my choice.) I try to change the font using what I find in posts and documentation like

plot( title="foobar", titlefont=font(14,"Arial") )

or

plot( title="foobar", titlefontfamily="Arial" )

but these do not work. I try different font names and basically nothing works. I get a change with computer modern, serif, and 1 or 2 others. I found this dictionary of GR fonts in the source but, again, most of them don't work although I can get some italic or bold fonts with some combinations.

Things may be more difficult because I am on a mac. I am using Plots with the GR backend. I could possibly switch away from the GR backend but going away from Plots would be difficult.

How do I find out which fonts are available for use in Julia plots and use them on my machine? Is there a way to import fonts with GR or other packages?

2 Answers2

1

This might work for you.

using Plots
x = 0:0.1:2π
y = sin.(x)
plotfonts = Plots.font(40, "Helvetica")
plot(x, y, title="Helvetica 4ever", titlefont = plotfonts)

[lplot1

Perhaps you should try PyPlot.

daycaster
  • 2,655
  • 2
  • 15
  • 18
  • I stepped away from Makie after I found [this](https://stackoverflow.com/questions/69889175/quantization-distortion-in-x-axis-of-glmakie-plot-why/69943381). I played around with PyPlot and didn't have a whole lot more luck. I did end up sticking with GR and using Helvetica. We'll see how the people that want me to use Arial feel about it. – aquaticapetheory Apr 25 '22 at 20:32
  • This is most likely Nimbus Sans rather than Helvetica anyway ... a legal free clone of the expensive Helvetica (which was once licensed for MacOS). Not many people can tell the difference between Arial and Helvetica... More worrying is the poor typesetting of that example... what's up with that "i"? – daycaster Apr 25 '22 at 22:10
1

I believe there is no such parameter. However you can use LaTeX formatting with Plots!

using LaTeXStrings, Plots

plot( title=L"x, y\mathbf{\ this\ is\ in\ bold}\mathrm{\ This\ is\ normal\ text}")

enter image description here

Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • What are you referring to when you say "there is no such parameter?" The arguments `titlefont` and `titlefontfamily` I have in the examples are both documented and they do work except for a very limited set of fonts. – aquaticapetheory Apr 27 '22 at 11:58
  • They do not support the font weight as far as I know (you were asking about the Bold font) – Przemyslaw Szufel Apr 27 '22 at 12:02
  • Using `font("Helvetica Bold")` does work. But there is no argument like `titlefontweight` for font weight specifically as in MATLAB, that is true. – aquaticapetheory Apr 27 '22 at 12:08
  • OK! I did not know that "Helvetica Bold" would work! I always used to resort to LaTeX formatting (anyway my plots always end up at PGFPlotsX) – Przemyslaw Szufel Apr 27 '22 at 12:22