Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent matplotlib from interpreting underscore as subscript in plot title

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.

like image 695
Dave Avatar asked Feb 23 '15 18:02

Dave


People also ask

How do you write a subscript in Matplotlib title?

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.

What is the function of PLT title () method in Matplotlib?

title() The title() method in matplotlib module is used to specify title of the visualization depicted and displays the title using various attributes.

How do you plot subscripts in Python?

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.


1 Answers

Probably something like this (untested):

title = 'I_hate_subscripts'
title = title.replace('_', '\_')
plt.title(title)
like image 126
Bas Swinckels Avatar answered Nov 15 '22 07:11

Bas Swinckels