Search code examples
pythonmatplotlibfontsvisualization

Matplotlib labels: greek letter + italic + black font


I am trying to add a greek letter that is in black font and italic font at the same time. In this case is just bold. I am not sure if its possible the combination of the three.

import matplotlib.pyplot as plt
plt.figure()
plt.plot()
plt.xlabel(r'$ \it{\bf{\mu_{0}}}$ H  (mT)',fontsize = 12, fontweight='bold')
plt.show()

enter image description here


Solution

  • According to the Matplotlib Documentation may use a combination of \mathbf for italic bold math font and a definition of the font directly.

    import matplotlib.pyplot as plt
    
    plt.rcParams['mathtext.fontset'] = 'custom'
    plt.rcParams['mathtext.bf'] = 'cm:italic:bold'
    
    plt.xlabel(r'$\mathbf{\mu_{0}}$ H  (mT)', fontsize=12, fontweight='bold')
    plt.show()
    

    enter image description here