Skip to content
Advertisement

How to italicize a string with underscore in the title of a plot

I would like to title a chart in seaborn as –

countplot of adult_male by alive

I found an old Jupyter Notebook document where someone used $ to wrap around the word to italicize. However, this does not work if there is an underscore. See the code below –

JavaScript

How do I fix the title?

Enter image description here

Advertisement

Answer

This works in a Jupyter Notebook document and a Python console.

JavaScript

As Trenton kindly pointed out, using an ANSI escape code to italicize doesn’t work when plotting.

JavaScript

The above works.

JavaScript

This doesn’t.

Advertisement