How to determine which fonts are available and use them in Julia plots?

1.6k views Asked by At

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

There are 2 answers

4
Przemyslaw Szufel On

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

2
daycaster On

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.