首页 文章

Matplotlib需要帮助使用下载的字体gill sans什么是字体系列

提问于
浏览
0

诺布在这里 . 我无法找出正确的matplotlib线来使用我新加载的gillius字体 .

所以我在我的机器ttf-adf-gillius上安装了arkandis数字代工厂的gillius字体

这是我“认为”它所说的地方

usr / share / fonts / truetype / adf / GilliusADF-Regular.otf:Gillius

ADF:风格=普通

因此,如果我想在导入matplotlib的Python 3.4程序中使用它 . 我设置了font_family ='Gillius'并且程序找不到它 . 我应该如何设置字体系列才能使用我的字体?

这是来自我的python程序的示例消息

警告(来自警告模块):文件“/usr/lib/python3/dist-packages/matplotlib/font_manager.py”,第1279行

(prop.get_family(),self.defaultFamily [fontext]))UserWarning:findfont:找不到字体系列['Gillius'] . 回到Bitstream Vera Sans

警告(来自警告模块):文件“/usr/lib/python3/dist-packages/matplotlib/font_manager.py”,第1289行

UserWarning)UserWarning:findfont:无法匹配:family = Bitstream Vera Sans:style = normal:variant = normal:weight = normal:stretch = normal:size = 20.0 . 返回/usr/share/matplotlib/mpl-data/fonts/ttf/cmmi10.ttf

我已经尝试过使用建议的链接How to use a (random) *.otf or *.ttf font in matplotlib?

但它似乎没有做任何事情 . 我的问题是假设字体安装正确我应该输入的字体系列是什么让matplotlib使用它?

1 回答

  • 0

    好吧,我认为这是一种基于我所获得的所有伟大帮助来实现它的方法 . 谢谢大家 . 我是matplotlib的新手,所以如果我搞砸了很乐意纠正它 .

    import matplotlib
    import matplotlib.font_manager as fm
    from matplotlib import pyplot as plt
    
    
    font = fm.FontProperties(
           family = 'Gill Sans',
           fname = '/usr/share/fonts/truetype/adf/GilliusADF-Regular.otf')
    
    data = range(5)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.bar(data, data)
    plt.ylabel('some y numbers')
    plt.xlabel('some x numbers')
    ax.set_yticklabels(ax.get_yticks(), fontproperties = font)
    ax.set_xticklabels(ax.get_xticks(), fontproperties = font)
    ax.set_title('this is a test of Gill sans font')
    plt.show()
    

相关问题