一つの文章の中でフォントスタイルを変えることはできないかと調べていて見つけたのがこれ。
https://github.com/znstrider/highlight_text
サンプルコードは以下の通り。< > で囲った文字列のプロパティを順に指定することにより、フォントのスタイルを変えることができる。
#https://github.com/znstrider/highlight_text
import matplotlib.pyplot as plt
from highlight_text import ax_text
import numpy as np
def main():
fsz=10
xmin,xmax,dx= 0,2,0.5
ymin,ymax,dy= 0,2,0.5
iw,ih=5,5
plt.figure(figsize=(iw,ih),facecolor='w')
plt.rcParams['font.size']=fsz
plt.rcParams['font.family']='sans-serif'
plt.xlim([xmin,xmax])
plt.ylim([ymin,ymax])
plt.xticks(np.arange(xmin,xmax+dx,dx))
plt.yticks(np.arange(ymin,ymax+dy,dy))
plt.xlabel('x_axis')
plt.ylabel('y_axis')
text = 'Highlight-text can change the font property\n \
of a part in a sentence as shown below.\n \
This is <Red>. \n \
This is <Lime>.\n \
This is <Blue>.'
ax_text(
x=1,
y=1,
s=text,
ha='center',
va='center',
fontsize=fsz,
color='#000000',
highlight_textprops=[
{"color": "#ff0000", 'fontweight': 'bold'},
{"color": "#00ff00", 'fontweight': 'bold'},
{"color": "#0000ff", 'fontweight': 'bold'}]
)
plt.show()
#---------------
# Execute
#---------------
if __name__ == '__main__': main()
以 上