Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
914 views
in Technique[技术] by (71.8m points)

python - Bold font weight for LaTeX axes label in matplotlib

In matplotlib you can make the text of an axis label bold by

plt.xlabel('foo',fontweight='bold')

You can also use LaTeX with the right backend

plt.xlabel(r'$phi$')

When you combine them however, the math text is not bold anymore

plt.xlabel(r'$phi$',fontweight='bold')

Nor do the following LaTeX commands seem to have any effect

plt.xlabel(r'$f phi$')
plt.xlabel(r'$mathbf{phi}$')

How can I make a bold $phi$ in my axis label?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unfortunately you can't bold symbols using the bold font, see this question on tex.stackexchange.

As the answer suggests, you could use oldsymbol to bold phi:

r'$oldsymbol{phi}$'

You'll need to load amsmath into the TeX preamble:

matplotlib.rc('text', usetex=True)
matplotlib.rcParams['text.latex.preamble']=[r"usepackage{amsmath}"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...