Prevent matplotlib from interpreting underscore as subscript in plot title

matplotlib, python

Solution

Probably something like this (untested):

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

Problem

I'm trying to put a filename, that includes underscores, as the `title` of a plot. This gets rendered as defining a subscript character, since by default I have LaTeX interpretation on. I'd like to prevent matplotlib from applying LaTeX to this string, while leaving my default `text.usetex` as `True` in my matplotlib configuration file. How do I do this? In my version, `1.3.1` (Ubuntu 14), I do not have an option to pass in a `usetex` keyword argument, as indicated in the documentation.

Original source