在matplotlib中禁用tex解释器 [英] Disable tex interpreter in matplotlib

查看:180
本文介绍了在matplotlib中禁用tex解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用matplotlib(通过安装在os x yosemite上的anaconda-spider)生成图,并在其上贴上标签(未由tex解释). 这是示例代码:

I would like to produce plots using matplotlib (through anaconda-spider installed on os x yosemite) and put labels on it not interpreted by tex. Here is the sample code:

# -*- coding: utf-8 -*-
import matplotlib.pyplot as pp
my_rc_param = {'text.usetex': False}
pp.figure()
pp.rcParams.update(my_rc_param)
pp.plot(range(10))
pp.xlabel('$x$')

我想确切地看到字符串$ x $作为x标签.反过来,我得到了数学模式的乳胶x. 我也曾尝试未成功地提出以下序言:

I would like to see exactly the string $x$ as x label. In turn, I get the math-mode latex x. I have also tried, unsuccessfully, to put the following preamble:

from matplotlib import rc
rc('text', usetex=False) 

有没有办法强迫普通口译员? 还是我应该将其视为错误?

Is there a way to force a plain interpreter? Or should I consider this as a bug?

推荐答案

您没有获得任何乳胶模式.您只需使用matplotlib的 mathtex 功能.使用乳胶是另一回事.我检查了是否可以关闭matplotlib的mathtex,并且对此有一个安静的问题(看到这里).但是,解决此问题的方法是避免数学运算只将$符号转义为'\':

You are not getting any latex mode. You are simply using the mathtex feature of matplotlib. Using latex is a different thing. I checked whether it is possible to switch off mathtex for matplotlib, and there is a quiet recent issue on this (see here). However, the way to sort out this problem consist is avoiding the math just escaping the $ symbol with '\':

pp.xlabel('\$x\$')

只需删除所有与text.usetex相关的内容,即可在此处尝试完成其他操作.

Just remove all the stuff related to the text.usetex as you are trying to do a complete different thing here.

这篇关于在matplotlib中禁用tex解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆