Sie können .ttf Dateien aus dem Repo auf github 'Fonts' Google. Sie können dort eine Schriftart aus der Liste auswählen und einen Link zur .ttf-Datei finden. Wenn Sie beispielsweise in das Verzeichnis "Gleich" wechseln, finden Sie eine Datei mit dem Namen "Alike-Regular.ttf", deren URL lautet: https://github.com/google/fonts/blob/master/ofl/alike/Alike-Regular.ttf.
Sobald Sie Ihre Schrift finden, können Sie das folgende Snippet verwenden es in matplotlib geladen werden "on the fly", eine temporäre Datei mit:
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()
Ergebnis:
https : //stackoverflow.com/questions/7726852/how-to-use-a-random-otf-o--ttf-font-in-matplotlib – Oz123
Was meinst du mit "on the fly"? Möchten Sie den Download überspringen und direkt von Google laden? – Shovalt