Matplotlib标记注释字体大小在PDF中不缩小到1pt以下

2024-10-01 05:02:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码中有两个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未缩放到fontsize=1以下

Illustration of the problem

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

我希望蓝色文本缩小比例,以便整齐地与红色圆形标记相匹配。有人能提出解决办法吗

谢谢


Tags: 文本ax比例colorlightcenterpowerxy
1条回答
网友
1楼 · 发布于 2024-10-01 05:02:05

我认为最小字体点大小为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,

相关问题 更多 >