【问题标题】:text, usetex=true setting renders the axis labels as welltext, usetex=true 设置也渲染轴标签
【发布时间】:2013-09-11 11:17:53
【问题描述】:

我今天尝试在图形中渲染一些 TeX,但没有成功。我意识到,matplotlibrc 文件中的text.usetex 设置为False。 当我将rc('text', usetex=True) 添加到我的脚本时,轴标签也会呈现为 TeX,这是不可取的。 我不记得在 matplotlib 1.3.0 之前设置过这个,而且我绝对不记得渲染 TeX 有任何困难。

还有其他人遇到这种情况吗?

例子:

import matplotlib.patheffects as PathEffects

# matplotlib.rc('text', usetex=True)

fig = plt.figure(figsize=(4,4))
ax = fig.add_axes([0,0,0.9,1])
ax.imshow(randn(20,20))
txt = ax.text(0.1, 0.5, r"Some \LaTeX\ $\alpha=\beta$", transform=ax.transAxes,fontsize=16)
txt.set_path_effects([PathEffects.Stroke(linewidth=3, foreground="w"), PathEffects.Normal()])

生产:

取消注释 `matplotlib.rc('text', usetex=True)' 行,产生:

【问题讨论】:

    标签: python matplotlib tex


    【解决方案1】:

    您的“问题”并不是真正的问题,但我假设您遇到以下问题:

    您想使用乳胶字体向绘图中添加一些文本,或者只是添加数学而不使用rc('text', usetex=True)(请注意,在默认的 rcparams 文件中,它声明这会影响 all 文本)。

    这是可以做到的:

    import matplotlib.pylab as plt
    
    fig = plt.figure()
    plt.annotate(r"$\mathcal{G}r \epsilon \epsilon \kappa$", xy=(5, 2), size=26)
    plt.annotate(r"default font", xy=(2, 5), size=16)
    plt.annotate(r"latex font", xy=(2, 7), size=20, family='computer modern roman')
    plt.plot(range(10))
    plt.xlabel("some string")
    

    希望能有所帮助!

    【讨论】:

    • 嗨,格雷格,我想我还不够清楚:除非usetex=True,否则不会渲染 TeX
    • 我在原始问题中添加了一个示例来解释问题。
    • 我现在看到了您的问题,确实我认为 matplotlib 目前不会支持您想要的行为。理想情况下,传递给 ax.text(...) 的 arg usetex=True 就是您想要的。也许在github上提出这个问题?
    猜你喜欢
    • 2015-05-30
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多