Sunday, 4 August 2019

matplotlib: Can I use a secondary font for missing glyphs?

The font I want to use doesn't have all the symbols I need. Is it possible to have matplotlib use a different font if a symbol is missing?

Here is a minimal example:

import matplotlib.pyplot as plt

fig = plt.figure()
plt.axis([0, 8, 0, 6])

t = u'abcde♥'

plt.text(4.5, 4, 'DejaVu Sans:', horizontalalignment='right')
plt.text(5, 4, t, {'family':'DejaVu Sans'})

plt.text(4.5, 3, 'Noto Sans:', horizontalalignment='right')
plt.text(5, 3, t, {'family':'Noto Sans'})

plt.text(4.5, 2, 'Noto Sans Symbols2:', horizontalalignment='right')
plt.text(5, 2, t, {'family':'Noto Sans Symbols2'})

plt.show()

And the output:

And the output.

Noto Sans is missing the heart symbol while Noto Sans Symbols2 is missing the letters. I'm trying to get something like the DejaVu Sans example but with letters from Noto Sans and the heart from Noto Sans Symbols2.



from matplotlib: Can I use a secondary font for missing glyphs?

No comments:

Post a Comment