How would I get a Bold font type in the annotate!()
function using Plots
with the GR
backend?
Have you tried using bold LaTeXStrings?
Similarly to this example.
MWE:
using LaTeXStrings, Plots; gr()
plot(sin)
str = "I\\ am\\ bold"
annotate!(0, 0, L"\textbf{%$str}")
Thanks.
I tried to avoid LaTeXStrings
.
- Is there a way to use the default GR sans serif font with LaTeXStrings?
- Is there a way around this?
You could use bold Unicode characters, if your font supports them:
julia> boldstring(s::AbstractString) = map(c -> 'a' ≤ c ≤ 'z' ? c + ('𝐚'-'a') : 'A' ≤ c ≤ 'Z' ? c + ('𝐀'-'A') : c, s)
boldstring (generic function with 1 method)
julia> boldstring("The quick brown fox jumped over the lazy dog.")
"𝐓𝐡𝐞 𝐪𝐮𝐢𝐜𝐤 𝐛𝐫𝐨𝐰𝐧 𝐟𝐨𝐱 𝐣𝐮𝐦𝐩𝐞𝐝 𝐨𝐯𝐞𝐫 𝐭𝐡𝐞 𝐥𝐚𝐳𝐲 𝐝𝐨𝐠."
(This only gives you bold with [A-Za-z]
, of course. You can do accented characters too if you first normalize the string s
to NFD.)
This is Plots
’ best friend. For consistency, you should use fontfamily = "Computer Modern"
using Plots
gr()
plot(sin)
str = "I am bold"
annotate!(0, 0, (str, "Helvetica Bold"))
2 Likes
Excellent.
Here is the list of GR bold fonts for reference.
1 Like
Thank you all for the different takes on the topic.