防止 matplotlib 将下划线解释为绘图标题中的下标

Prevent matplotlib from interpreting underscore as subscript in plot title

我正在尝试将包含下划线的文件名作为情节的 title。这被渲染为定义下标字符,因为默认情况下我有 LaTeX 解释。我想阻止 matplotlib 将 LaTeX 应用于此字符串,同时在我的 matplotlib 配置文件中将我的默认值 text.usetex 保留为 True

我该怎么做?

在我的版本 1.3.1 (Ubuntu 14) 中,我没有传递 usetex 关键字参数的选项,如文档中所示。

可能是这样的(未经测试):

title = 'I_hate_subscripts'
title = title.replace('_', '\_')
plt.title(title)