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.
MatPlotLib with PythonUse xlabel and ylabel with subscripts in the text. Use the legend() method to place a legend in the plot. Adjust the padding between and around subplots. To display the figure, use the show() method.
title() The title() method in matplotlib module is used to specify title of the visualization depicted and displays the title using various attributes.
To make subscripts, you have to write the expression inside the dollar sign using the _ and ^ symbols. If you use the _ symbol, the superscript will be under the character. If you use the ^ symbol, the superscript will be over the character.
Probably something like this (untested):
title = 'I_hate_subscripts'
title = title.replace('_', '\_')
plt.title(title)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With