2017-05-09 113 views
0

我正在Jupyter中使用Matplotlib進行繪圖。我遇到的問題是Mathjax使用默認的Maplotlib字體渲染數學字體(我相信Dejavu Sans)。我想使用Times New Roman,所以這個問題讓我的情節有兩種不同的字體。我已經包含了一個簡短的例子,它強調了Jupyter和Matplotlib的問題(另外,爲了給出適當的參考,我使用了here中的代碼並添加了幾行代碼)。Jupyter的Mathjax/Matplotlib字體

%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() 

Plot with two fonts

+1

除非我記錯了這有什麼都沒有做MathJax;它是Matplotlib中的TeX渲染代碼。 MathJax在HTML中呈現數學。你能編輯你的問題嗎?這是寫的誤導。 (我恰好在尋找如何在Jupyter中配置MathJax。) –

+0

我曾經建議編輯標題爲「如何將matplotlib mathtext字體更改爲Times New Roman」以及一些小編輯來刪除對Mathjax的引用,但他們被拒絕。 – saintsfan342000

回答

1

除了你已經有了一個嘗試這些設置:
plt.rcParams['mathtext.default'] = 'rm'
plt.rcParams['mathtext.fontset'] = 'stix'