Disable tex interpreter in matplotlib

时光毁灭记忆、已成空白 提交于 2019-12-24 16:22:46

问题


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$')

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?


回答1:


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\$')

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



来源:https://stackoverflow.com/questions/36515347/disable-tex-interpreter-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!