how to set up a custom font with custom path to matplotlib global font?

后端 未结 1 1479
别那么骄傲
别那么骄傲 2020-12-03 08:36

There is a custom font in my app

app_path=\'/home/user1/myapp\'
fname=\'/home/user1/myapp/font/myfont.ttf\'

To setup

相关标签:
1条回答
  • 2020-12-03 08:45

    Solved the problem like this:

    import matplotlib.font_manager as font_manager
    
    font_dirs = ['/my/custom/font/dir', ]
    font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
    font_list = font_manager.createFontList(font_files)
    font_manager.fontManager.ttflist.extend(font_list)
    
    mpl.rcParams['font.family'] = 'My Custom Font'
    

    The fontpaths kwarg can also be a string in case you only have a single directory to import from.

    0 讨论(0)
提交回复
热议问题