Matplotlib, Python: Part Of Title In Bold Font
I would like to create an axis title that has part of it in bold font. For example, I am comparing two data sets and computing R^2, and if there is statistical significance, I woul
Solution 1:
The following seems to only work on matplotlib version 2 or above.
One can use bold MathText inside the title to make part of the text bold, e.g. r"$\bf{0.333}$"
. Note that this is a raw string (r""
). If we want to format the string with brackets, they have to be double escaped,
`r"$\bf{{{x}}}$".format(x=0.333)`
Complete example:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = plt.subplot()
# example R^2
r1 = np.random.random()
ax1.set_title(r'non-bold part of title, $R^2$: $\bf{{{a}}}$'.format(a=np.around(r1, 3) ) )
plt.show()
Post a Comment for "Matplotlib, Python: Part Of Title In Bold Font"