2014-01-30 4 views
23

matplotlib의 기본 글꼴을 Helvetica Neue로 변경하려고합니다. 내 Mac에서 EPD/Canopy를 사용하여 모든 것이 잘 돌아갔다.matplotlib의 기본 글꼴을 변경하십시오.

지금 우분투에서 동일한 작업을 시도하면 작동하지 않습니다.

  1. 설치된 헬 베티 노이에을

    $ fc-match 'Helvetica Neue':Light 
    HelveticaNeue-Light.otf: "Helvetica Neue" "細體" 
    
  2. 는 ODT/dfont TTF로 변환 :

    fondu -show HelveticaNeue.dfont 
    
  3. 변경된 matplotlibrc에

    ,536,913을

    내가 무슨 짓을
    $ cat ~/.config/matplotlib/matplotlibrc 
    ... 
    font.family: Helvetica Neue 
    

    나는 또한 시도했다 :

    font.family: sans-serif 
    font.sans-serif: Helvetica Neue 
    
  4. 나는 글꼴 캐시

    rm ~/.config/matplotlib/fontList.cache 
    

을 제거하지만이 단계 중 어느 것도 나를 위해 작동하지 않습니다.

$ python -c 'from matplotlib import pyplot as plt; plt.plot(1); plt.savefig("/tmp/test.png")' 
    /usr/local/lib/python2.7/dist-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/font_manager.py:1236: 
    UserWarning: findfont: Font family ['Helvetica Neue'] not found. Falling back to Bitstream Vera Sans 

(prop.get_family() self.defaultFamily는 [fontext]) ')

버전 I은 또한 ~/.config/matplotlib/fonts/ttf에 폰트를 이동하려고 1.3.0

$ python -c 'import matplotlib; print matplotlib.__version__' 
    1.3.0 

이지만 didn를 일하지 마라.


는 편집 : 으로 내가 특정 텍스트를 특정 글꼴을 선택하려고 제안했다.

import matplotlib as mpl 
mpl.use('Agg') 
import matplotlib.pyplot as plt 
import matplotlib.font_manager as font_manager 

path = '/home/<myusername>/.fonts/HelveticaNeue.ttf' 

prop = font_manager.FontProperties(fname=path) 
prop.set_weight = 'light' 
mpl.rcParams['font.family'] = prop.get_name() 
mpl.rcParams['font.weight'] = 'light' 

fig, ax = plt.subplots() 
ax.set_title('Text in a cool font', fontproperties=prop, size=40) 
plt.savefig('/tmp/test2.png') 

하지만 차이는 없습니다.

/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/font_manager.py:1236: 
UserWarning: findfont: Font family ['Helvetica Neue'] not found. Falling back to Bitstream Vera Sans 

그러나이 Helvetica/Helvetica Neue 글꼴에서만이 문제가 발생하는 것으로 보입니다. (prop.get_family(), self.defaultFamily는 [fontext]))

+1

기본값을 변경하기 전에 새 글꼴을 직접/명시 적으로 사용할 수 있었습니까? http://stackoverflow.com/a/18821968/1643946은 python/mpl에서 사용할 수있는 글꼴 목록을 표시하는 한 가지 방법을 보여줍니다. 'plt.text (1, 1,'rattling ', font_family = "Helvetica Neue ")'. http://stackoverflow.com/a/16574948/1643946 – Bonlenfum

+0

박람회 지점을 참조하십시오. 나는 성공하지 못했습니다. 그에 따라 질문을 수정했습니다. – gozzilli

+0

master 브랜치에서이 설치를 시도해 볼 수 있습니까? 최근에는 글꼴 조회와 관련된 많은 작업이있었습니다. 그것은 또한 이름에 ASCII가 아닌 ASCII 글꼴이있는 것처럼 보입니다. iirc에는 작동하지 않는 버그가 있습니다. – tacaswell

답변

13

이 영구적 글꼴 변경되지 않습니다, 그러나 그것은

matplotlib.rc('font', family='sans-serif') 
matplotlib.rc('font', serif='Helvetica Neue') 
matplotlib.rc('text', usetex='false') 
matplotlib.rcParams.update({'font.size': 22}) 
+1

문제는 기본 동작이 아니라 내 Helvetica Neue 글꼴을 인식하지 못한다는 것입니다. 나는 github에 버그를 제기했다. – gozzilli

+0

나는 EPD 파이썬 버전 (https : //www.enthought.com/products/epd /) 및 Helvetica Neue가 인정됩니다. – Brian

+1

좋습니다, 감사합니다. 어떤 OS에서? Mac 용 EPD (Canopy 실제로)에서도 작동하지만 Ubuntu에서는 작동하지 않습니다. – gozzilli

8

우분투 14 시도 할 가치가있다.04 LTS

업로드를 글꼴

sudo cp NotoSansKR-Regular.otf /usr/share/fonts/ 

업데이트 당신은 글꼴 목록

fc-list 

다시 시작 ipython 등을 확인할 수 있습니다

sudo fc-cache -fv 

글꼴 캐시가 글꼴을 확인 목록

글꼴 캐시가 나를 위해 다른 장소 (.cache /하기 matplotlib/fontList.cache)에 표시

plt.title(u'한글 제목') 
plt.xlabel(u'한글 축 이름') 
plt.plot(range(5)) 
+0

좋지만 작동하지 않습니다 :'[f.name in f in matplotlib.font_manager.fontManager.ttflist]''AttributeError : 'module'객체의 속성이 'font_manager''가 아닙니다 –

+1

이 명령을 사용 해보시겠습니까? import matplotlib.font_manager''' –

+0

때때로 새로운 글꼴을 사용하기 위해서'matplotlib.font_manager._rebuild()'가 필요합니다 – Tobias

1

그립니다 글꼴 이름

import matplotlib.pyplot as plt 
from matplotlib import rcParams 
rcParams['font.family'] = 'Noto Sans Korean' 

을 가져 가라. 그리고 사실은 어떻게 든 다른 장소에서 그 세를 가지기 전에 :/

어쩌면 홈 디렉토리에서 검색해보십시오 :

find ~/ -name fontList.cache -exec rm {} \; 
1

김 이미 도입 동적 솔루션은 완벽하게 작동하고, 여기에 일을 두 가지 다른 방법입니다 정적 인 경우에도 마찬가지입니다.

먼저 matplotlib의 줄을 rc 파일에 넣을 수 있습니다. 파일 위치 및 세부 설정에 대한 자세한 내용은 this page을 참조하십시오.

font.family : NanumGothic 

둘째, ipython으로 작업하는 경우 글꼴 설정을위한 몇 가지 명령을 대화 형 셸의 구성 파일에 넣을 수 있습니다. 보통 ~/.ipython/어딘가에있는 ipython_config.py라는 파일을 찾으십시오. 그런 다음 c.InteractiveShellApp.exec_lines 목록에 두 줄을 더 추가하십시오. 항상 전

c.InteractiveShellApp.exec_lines = [ 
    "import matplotlib as mpl", 
    "mpl.rcParams['font.family'] = 'NanumGothic'" 
] 

는 스크립트 수입하기 matplotlib 때 글꼴을로드로 쉘 스크립트를 실행 어떤 환경에서 작동합니다.

관련 문제