1

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()
Alex
  • 347
  • 1
  • 10
  • Possible duplicate of [Make part of a matplotlib title bold and a different color](https://stackoverflow.com/questions/34937048/make-part-of-a-matplotlib-title-bold-and-a-different-color) – Alexandre B. Apr 13 '20 at 09:52
  • I do not understand it. I tried: `text = 'Positives \n +'` and `plt.title(r"$\bf{" + str(text) + "}$")` What is wrong with it, please? – Alex Apr 13 '20 at 10:03
  • O I tried: `plt.title(r"\textbf{Positives \n +}")` – Alex Apr 13 '20 at 10:12

1 Answers1

1

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!

Alexandre B.
  • 5,387
  • 2
  • 17
  • 40
  • Thank you very much, it helped. And is it possible to write the sign plus in bold too? – Alex Apr 13 '20 at 10:40