È possibile ottenere file dal repository di Google 'font' .ttf sul github. È possibile selezionare un carattere dall'elenco lì e trovare un collegamento al file .ttf. Ad esempio, se vai nella directory "uguale", troverai un file chiamato "Alike-Regular.ttf", il cui URL è: https://github.com/google/fonts/blob/master/ofl/alike/Alike-Regular.ttf.
Una volta trovato il tipo di carattere, è possibile utilizzare il seguente frammento di caricarlo in matplotlib "al volo", usando un file temporaneo:
from tempfile import NamedTemporaryFile
import urllib2
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
github_url = 'https://github.com/google/fonts/blob/master/ofl/alike/Alike-Regular.ttf'
url = github_url + '?raw=true' # You want the actual file, not some html
response = urllib2.urlopen(url)
f = NamedTemporaryFile(delete=False, suffix='.ttf')
f.write(response.read())
f.close()
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
prop = fm.FontProperties(fname=f.name)
ax.set_title('this is a special font:\n%s' % github_url, fontproperties=prop)
ax.set_xlabel('This is the default font')
plt.show()
Risultato:
https : //stackoverflow.com/questions/7726852/how-to-use-a-random-otf-or-ttf-font-in-matplotlib – Oz123
Cosa intendi con "al volo"? Vuoi saltare il download e caricare direttamente da Google? – Shovalt