Bold title - subplots

I have a script for subplot with params that set font. How to do an exception to have fig1.set_title bold? Thank you

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D                 # 3d graph
from mpl_toolkits.mplot3d import proj3d                 # 3d graph   
plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"]
plt.rcParams['text.latex.preamble']=[r"\usepackage{bm}"]
params = {'text.usetex' : True,
          'font.size' : 28,
          'font.family' : 'lmodern',
          'text.latex.unicode': True,
          }
plt.rcParams.update(params)
# Plot subplot 
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 2, figsize=(10,13))
fig1 = plt.subplot(421)
fig1.set_title('AAAAA \n +', fontweight='bold', color='red', pad=50)
plt.axis('off')
fig2 = plt.subplot(422)
fig3 = plt.subplot(423, projection = '3d') 
fig4=plt.subplot(424)
fig5=plt.subplot(425)
fig6=plt.subplot(426)
fig7=plt.subplot(427)
fig8=plt.subplot(428)
plt.tight_layout()
plt.show()

Answers

Try:

def setBold(txt): return r"$\bf{" + str(txt) + "}$"

plt.title(setBold("AAAAA") + '\n' + setBold('+'))

The problem comes from "\n". Putting newline in matplotlib label with TeX advices seperating the \n from the Latex formatting.

Hope that helps!

Posted on by Alexandre B.

Relevant tags