粗体标题 - 子图
Bold title - subplots
我有一个带有设置字体参数的子图脚本。如何做一个例外让 fig1.set_title 加粗?谢谢
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()
尝试:
def setBold(txt): return r"$\bf{" + str(txt) + "}$"
plt.title(setBold("AAAAA") + '\n' + setBold('+'))
问题来自"\n"
。 Putting newline in matplotlib label with TeX 建议将 \n
与 Latex 格式分开。
希望对您有所帮助!
我有一个带有设置字体参数的子图脚本。如何做一个例外让 fig1.set_title 加粗?谢谢
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()
尝试:
def setBold(txt): return r"$\bf{" + str(txt) + "}$"
plt.title(setBold("AAAAA") + '\n' + setBold('+'))
问题来自"\n"
。 Putting newline in matplotlib label with TeX 建议将 \n
与 Latex 格式分开。
希望对您有所帮助!