【问题标题】:Mathjax/Matplotlib font in JupyterJupyter 中的 Mathjax/Matplotlib 字体
【发布时间】:2017-10-08 03:18:57
【问题描述】:

我正在 Jupyter 中使用 Matplotlib 进行绘图。我遇到的问题是 Mathjax 使用默认的 Maplotlib 字体(我相信 Dejavu Sans)呈现数学字体。我想使用 Times New Roman,所以这个问题使我的情节有两种不同的字体。我提供了一个简短的示例,突出显示了我在使用 Jupyter 和 Matplotlib 时遇到的问题(另外,为了提供适当的参考,我使用了来自 here 的代码,并添加了几行代码)。

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)

plt.rcParams['font.family'] = 'Times New Roman'

plt.xlabel('See, this is in Times New Roman 12345')
plt.ylabel(r'$but-this-is-not-12345$')
plt.title(r'This has both Times New Roman $and-Mathjax$')
plt.grid(True)
plt.savefig("test.png")
plt.show()

【问题讨论】:

  • 除非我弄错了,否则这与 MathJax 没有任何关系;这是 Matplotlib 中的 TeX 渲染代码。 MathJax 在 HTML 中呈现数学。你能编辑你的问题吗?它是误导性的,因为它是写的。 (我恰好在寻找如何在 Jupyter 中配置 MathJax。)
  • 我曾提议将标题编辑为“如何将 matplotlib mathtext 字体更改为 Times New Roman”并进行一些小的编辑以删除对 Mathjax 的引用,但被拒绝了。

标签: matplotlib fonts jupyter


【解决方案1】:

在已有设置的基础上尝试以下设置:
plt.rcParams['mathtext.default'] = 'rm'
plt.rcParams['mathtext.fontset'] = 'stix'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2016-05-14
    • 2013-10-05
    • 1970-01-01
    • 2019-09-27
    相关资源
    最近更新 更多