use*_*817 18 python matplotlib
遵循这个例子:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
for i, label in enumerate(('A', 'B', 'C', 'D')):
ax = fig.add_subplot(2,2,i+1)
ax.text(0.05, 0.95, label, transform=ax.transAxes,
fontsize=16, fontweight='bold', va='top')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:

为什么我的标签正常重量,而文档显示这应该创建粗体字母A,B,C,D?
一个额外的信息,它给了我这个警告:
Warning (from warnings module):
File "C:\Python27\lib\site-packages\matplotlib\font_manager.py", line 1228
UserWarning)
UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=italic:variant=normal:weight=bold:stretch=normal:size=x-small. Returning C:\Python27\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf
Run Code Online (Sandbox Code Playgroud)
也许尝试使用这个 -
plt.rcParams['axes.labelsize'] = 16
plt.rcParams['axes.labelweight'] = 'bold'
Run Code Online (Sandbox Code Playgroud)
在您的程序中在全局级别执行此操作。
您问题中的示例适用于我的机器。因此,您肯定有图书馆问题。您是否考虑过使用乳胶来制作粗体文字?这里有一个例子
代码
import numpy as np
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 1)
ax0, ax1, ax2 = axs
ax0.text(0.05, 0.95, 'example from question',
transform=ax0.transAxes, fontsize=16, fontweight='bold', va='top')
ax1.text(0.05, 0.8, 'you can try \\textbf{this} using \\LaTeX', usetex=True,
transform=ax1.transAxes, fontsize=16, va='top')
ax2.text(0.05, 0.95,
'or $\\bf{this}$ (latex math mode with things like '
'$x_\mathrm{test}^2$)',
transform=ax2.transAxes, fontsize=10, va='top')
plt.show()
Run Code Online (Sandbox Code Playgroud)
不确定您是否仍然遇到该问题。我在 Anaconda/Spyder、Python 2.7 中尝试了你的代码。绘图显示为粗体标签(A、B、C、D)。我同意问题可能出在图书馆。尝试替换/更新 font_manager.py 或确认字体文件是否存在:
Lib\site-packages\matplotlib\mpl-data\fonts\ttf\
| 归档时间: |
|
| 查看次数: |
30925 次 |
| 最近记录: |