关闭TeX模式以获取matplotlib中刻度标记的指数表示法

时间:2019-02-22 12:25:43

标签: python matplotlib plot

我正在尝试关闭x和y-tick标签(对数y缩放)的TeX渲染。我遵循ImportanceOfBeingErnest问题中提供的this的建议,该建议适用于我的x轴,但不适用于y轴上的指数符号。

在下图中,您可以注意到,对于x-ticklabel,TeX渲染已关闭,但对于y-ticklabel,仍打开

问题:如何在我的案例中保持将标签符号保持为10 ^ -n来关闭y-tick标签的TeX模式?可能有骗子,但我很难找到它。


以下是可复制的代码:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
rc('text', usetex=True)

fig, ax = plt.subplots(figsize=(6,4))

# Define data
x = range(100)
y = np.logspace(-12, 0, 100)

# Plot data and label axis
plt.semilogy(x, y)
plt.xlabel('x-label', fontsize=20)
plt.ylabel('y-label', fontsize=20)
plt.xlim(0, 100)
plt.ylim(1e-12, 1)

# Increase fontsize for ticklabels for better identification
for tick in ax.xaxis.get_major_ticks():
    tick.label.set_fontsize(16) 
for tick in ax.yaxis.get_major_ticks():
    tick.label.set_fontsize(16)   

# Turn off the TeX rendering for x and y-ticklabels
ax.xaxis.get_major_formatter()._usetex = False
ax.yaxis.get_major_formatter()._usetex = False # This does not work

plt.show()

上面的代码生成以下图:

enter image description here

我的pythonmatplotlib版本是

import sys
import matplotlib

print (sys.version)
# 3.6.5 |Anaconda, Inc.| 

print (matplotlib.__version__)
# 2.2.2

0 个答案:

没有答案