【发布时间】:2019-04-17 19:49:55
【问题描述】:
(在 Win10 上使用 Python 3.6.1,在一个基本上只安装了 numpy/pandas/matplotlib 的 virtualenv 中,用于处理数字的东西。我没有安装 Tkinter,我更愿意保持这种方式。)
我有以下测试代码,试图静态呈现 MathML 文本:
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plot
def render(mathml):
plot.clf()
plot.rc('font', family='monospace', size=72)
plot.axis('off')
plot.text(0, 0, f'{mathml}')
plot.savefig(f'hax.png')
render('$lorem^{ipsum}$')
生成的test.png 以默认字体(DejaVu Sans Oblique)显示文本,而不是等宽字体:
明确指定字体(例如family='Courier New')也无效,更改输出格式也无效。文本已正确调整大小,并且没有出现错误或警告 - 输出只是没有显示正确的字体。
这里发生了什么?我该如何解决?
【问题讨论】:
-
我没有安装 Tkinter,我希望保持这种状态,
tkinter已经是 Python 标准库的一部分,所以它已经安装了。跨度> -
Windows 标准安装程序完全可以省略它(连同 IDLE)。
标签: python python-3.x matplotlib