簡體   English   中英

在Matplotlib刻度標簽中禁用Usetex

[英]Disabling usetex in matplotlib tick labels

我正在嘗試使用Python(版本3.5.3)和Matplotlib(版本2.0.2)創建圖形。 我想用在Latex中渲染的方程式來標記圖中的一個軸。 要渲染方程式,我需要使用amsmath和amsfonts軟件包。

我設法做到這一點的唯一方法是為matplotlib圖形中的所有文本全局設置usetex = True。 但是,這也會導致刻度標簽也以Latex呈現。 我可以預防這種情況嗎?

import numpy as np
import matplotlib.pyplot as plt
preamble='\\usepackage{amsmath}\n\\usepackage{amsfonts}'

plt.rc('text',usetex=True)
plt.rc('text.latex',preamble=preamble)

fig,ax=plt.subplots()

all_lambda = np.linspace(-6,2,1000)
ax.plot(all_lambda,np.exp(-np.exp(all_lambda)))
ax.set_xlim([-6,2])
ax.set_ylim([-0.1,1.1])
ax.set_xlabel(r'$\log\lambda$')
ax.set_ylabel(r'$\mathbb{P}(m=0\lvert \lambda)$')
fig.tight_layout()
plt.show()

matplotlib圖

也許您想使用MathText代替乳膠?

plt.rcParams["mathtext.fontset"] = "stixsans"

沒有乳膠的完整示例:

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["axes.labelsize"] = "large"
plt.rcParams["mathtext.fontset"] = "stixsans"


fig,ax=plt.subplots()

all_lambda = np.linspace(-6,2,1000)
ax.plot(all_lambda,np.exp(-np.exp(all_lambda)))
ax.set_xlim([-6,2])
ax.set_ylim([-0.1,1.1])
ax.set_xlabel(r'$\log\lambda$')
ax.set_ylabel(r'$\mathbb{P}(m=0\left| \lambda\right)$')
fig.tight_layout()
plt.show()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM