python - 增加 matplotlib 注释文本中的行间距

标签 python matplotlib

fig.text(0.6, 0.15,
         'Line 1\n'
         'Line 2\n'
         'Line 3')

在 matplotlib 中,有没有办法增加上面命令中两行之间的行距?我尝试插入额外的 \n 但这会使行间距太宽。

最佳答案

对于每个 .text() 语句,可选参数 linespacing 会将垂直行间距设置为等于字体大小的多个值。 例如,

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
for ea in range(5):
    fig.text(0.18 + 0.15*ea, 0.15,
             'Line 1\n'
             'Line 2\n'
             'Line 3', color='b', \
             linespacing = 1+ea)
plt.show()

结果图是:

enter image description here

关于python - 增加 matplotlib 注释文本中的行间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50869424/

相关文章:

python - TensorFlow 中相当于 PyTorch 中的 expand() 的函数是什么?

python - 增加pyplot游标中的有效数字

c# - 使用散列进行身份验证

python - LPTHW 练习 43 - 通过从字典返回构造函数来创建对象

python - 检测 OS X 中挂起的 python shell

python - Tensorflow 一种用于多输出模型的自定义指标

matplotlib - matplotlib 图的自定义背景部分

python - 我如何将垂直线添加到他们选择的 seaborn dist 地 block ? [单个地 block 中的多个分布]

python - 如何在 matplotlib 中为我的热图使用预制颜色图?

python - subplot2grid 中的条形图