47

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.

tmdavison
  • 64,360
  • 12
  • 187
  • 165
bgame2498
  • 4,467
  • 5
  • 15
  • 19

3 Answers3

89

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

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
17

activate latex text rendering

from matplotlib import rc
rc('text', usetex=True)

plt.title("This is title number: " + r"\textbf{" + str(number) + "}")
tmdavison
  • 64,360
  • 12
  • 187
  • 165
bgame2498
  • 4,467
  • 5
  • 15
  • 19
0

This post should answer your question on manipulating the title. You can use latex text rendering and call textbf for that particular part of the string.

Styling part of label in legend in matplotlib

Here is the documentation: http://matplotlib.org/users/usetex.html http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_title

Community
  • 1
  • 1
DeeGautam
  • 31
  • 5
  • 1
    External links can change, hence it is preferred to copy the interesting section of an external page in your comment. Copying the interesting section of an external page and citing where it's from is best! – Alex Fortin Feb 16 '18 at 21:52