【问题标题】:Matplotlib need help using a downloaded font gill sans what is the font familyMatplotlib 需要帮助使用下载的字体 gill sans 什么是字体系列
【发布时间】:2016-03-01 02:23:34
【问题描述】:

这里是菜鸟。我无法找出正确的 matplotlib 行来使用我新加载的 gillius 字体。

所以我在我的机器上安装了 arkandis digital foundry 的 gillius 字体 ttf-adf-吉利斯

这是我“认为”它放的地方

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

ADF:style=常规

如果我想在导入 matplotlib 的 Python 3.4 程序中使用它。我设置了 font_family= 'Gillius" 并且程序没有找到它。请问我应该设置什么字体系列来使用我的字体?

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

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

(prop.get_family(), self.defaultFamily[fontext])) 用户警告:findfont:字体 未找到家庭 ['Gillius']。回退到比特流 Vera 无

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

用户警告) 用户警告: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 使用它?

【问题讨论】:

  • 嘿汤姆,谢谢你的回复,但我在我的问题中提到了这一点,并说它不起作用。还是谢谢
  • This 可能会有所帮助...
  • 嘿底漆现场,感谢您找到它。尽管我进行了搜索,但我有点尴尬。我正在寻找向 linux 的过渡,并学习 Python 来破坏灵魂。有很多事情需要调整,但我想这与领土有关。

标签: matplotlib


【解决方案1】:

好的,我“认为”这是一种基于我在 SO 上获得的所有伟大帮助的方法。谢谢大家。我是 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()

【讨论】:

    猜你喜欢
    • 2013-09-19
    • 2014-05-19
    • 1970-01-01
    • 2015-12-07
    • 2018-04-18
    • 2014-02-02
    • 2022-01-21
    • 1970-01-01
    • 2016-10-16
    相关资源
    最近更新 更多