Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make part of a matplotlib title bold and a different color

I would like to change part of a title to be bold. For example:

plt.title("This is title number: " + str(number)) 

Given a title like the above, how would I bold the str(number) part.

like image 927
bgame2498 Avatar asked Jan 22 '16 00:01

bgame2498


People also ask

How do I bold a title in Matplotlib?

To set the Matplotlib title in bold while using "Times New Roman", we can use fontweight="bold".

How do I make text bold in Matplotlib?

Utilizing “Times New Roman” as the font for Matplotlib's bold label. We could use attribute fontweight=”bold” to get the Matplotlib label bold when utilizing “Times New Roman.”

How do I color text in Matplotlib?

To do this, I would use Latex to format the text. Then I would include the 'color' package, and set your colors as you wish. I would use this one, if only it were to work with the PDF backend :) For some reason, I can never get the axes placed properly on the canvas while I am working with the ps backend.


1 Answers

From matplotlib version 2 on, there is no need to use latex (which would require a working latex installation). One can use normal MathText to render part of the title in bold.

import matplotlib.pyplot as plt number = 2017 plt.title("This is title number: " + r"$\bf{" + str(number) + "}$") plt.show() 

enter image description here

like image 196
ImportanceOfBeingErnest Avatar answered Sep 19 '22 09:09

ImportanceOfBeingErnest