Bold Format Suptitle with Mathematical Expression

320 Views Asked by At

This line of code:

plt.suptitle("Observed and Predicted $U_{dec,c}$",x=mid,fontweight='bold')

Produces a suptitle like this:

enter image description here

However, I require the entire string to be in bold, including the mathematical expression, and for various reasons I need to use plt.suptitle, not plt.title. I would be grateful for any advice on how to do this.

2

There are 2 best solutions below

2
Abhyuday Vaish On BEST ANSWER

You can use \mathbf:

from numpy import *
from matplotlib.pyplot import *
import matplotlib.pyplot as plt

rcParams['mathtext.fontset'] = 'custom'
rcParams['mathtext.it'] = 'STIXGeneral:italic'
rcParams['mathtext.bf'] = 'STIXGeneral:italic:bold'

plt.suptitle(r"Observed and Predicted $\mathbf{U_{dec,c}}$", fontweight='bold')
plt.show()

Output:

enter image description here

Credits (for italic): https://stackoverflow.com/a/44790518

Here is a list of Latex symbols.

For more questions, you can checkout this.

1
mozway On

There are many options, a simple one is to use \mathbf:

plt.suptitle(r"Observed and Predicted $\mathbf{U_{dec,c}}$", fontweight='bold')

mathbf

You can find more options here.