2015-10-11 17 views
8

Matplotlib ile çizilen rakamlar için dizüstü bilgisayarımdan indirdiğim Roboto Condensed fontunu kullanıyorum. Yazı tipini "CSS @import" gibi, Google Fonts'dan içe aktarma ve matplotlib ile doğrudan kullanmanın mümkün olup olmadığını merak ediyorum.Google fontlarını Matplotlib ve Jupyter ile yükleyebilir miyim?

Python için Jupyter not defterini kullanıyorum. Bir yolu olabilir mi?

En

, F.

+0

https size yazı bulduğunuzda

, geçici bir dosya kullanarak, "anında" matplotlib içine yüklemek için aşağıdaki parçacığını kullanabilirsiniz : //stackoverflow.com/questions/7726852/how-to-use-a-random-otf-or-ttf-font-in-matplotlib – Oz123

+0

"Uçuşa" ne demek istiyorsun? İndirmeyi atlayıp doğrudan Google'dan yüklemek istiyor musunuz? – Shovalt

cevap

0

Sen github tarihinde google 'Fonts' repo dosyaları Ttf alabilirsiniz. Listeden bir yazı tipi seçebilir ve .ttf dosyasına bir bağlantı bulabilirsiniz. Örneğin, 'alike' dizinine girerseniz, URL'si: https://github.com/google/fonts/blob/master/ofl/alike/Alike-Regular.ttf olan 'Alike-Regular.ttf' adlı bir dosya bulacaksınız.

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() 

Sonuç:

Plot with custom google font

İlgili konular