Make part of the name matplotlib bold and a different color

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

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

Given a headline similar to the above, how would I highlight the part str(number).

+4
source share
3 answers

activate latex visualization

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

plt.title("This is title number: " + r"\textbf{" + str(number) + "}")
+1
source

From matplotlib version 2 on, there is no need to use latex (which will require a working latex installation). You can use regular MathText to render the part 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

+7
source

Source: https://habr.com/ru/post/1625423/


All Articles