首页 > 解决方案 > Matplotlib 标记注释字体大小在 PDF 中不会缩小到 1pt 以下

问题描述

我的代码中有两个 ax.annotate 语句。第一行文字我想变大。第二行文字应按比例缩小。

for i,j,k in zip(x_power,y_power,net_name_power):
    ax.annotate(str(k),  xy=(i, j), color='white', fontsize=1, weight='light', horizontalalignment='center', verticalalignment='bottom')
    ax.annotate('{} , {}'.format(str(round(i,3)),str(round(j,3))),  xy=(i, j), color='blue', fontsize=0.1, weight='light', horizontalalignment='center', verticalalignment='top')

ax.annotate 的字体大小不低于 fontsize=1。

问题说明

在图像中,白色文本是 fontsize=1,而蓝色文本是 fontsize=0.1。但正如人们所看到的,两个文本的大小相同。我正在使用plt.savefig('output.pdf')以 PDF 格式转储绘图 。

我希望蓝色文本按比例缩小,以便整齐地放入红色圆形标记中。有人可以提出解决方案吗?

谢谢 !

标签: pythonmatplotlibannotationssizemarker

解决方案


我相信最小字体点大小是 1 - 请参阅此处的源代码:

if size < 1.0:
    _log.info('Fontsize %1.2f < 1.0 pt not allowed by FreeType. '
              'Setting fontsize = 1 pt', size)
    size = 1.0

您可以尝试使用字符串描述符:

例如:fontsize='xx-small'

font_scalings = {
    'xx-small': 0.579,
    'x-small':  0.694,
    'small':    0.833,
    'medium':   1.0,
    'large':    1.200,
    'x-large':  1.440,
    'xx-large': 1.728,
    'larger':   1.2,
    'smaller':  0.833,
    None:       1.0,

推荐阅读