Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase line separation in matplotlib annotation text

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

In matplotlib is there a way to increase line spacing between 2 lines in the command above? I tried inserting an extra \n but that makes the line separation too wide.

like image 333
user308827 Avatar asked Mar 07 '23 00:03

user308827


1 Answers

With each .text() statement, optional parameter linespacing will set the vertical line spacing equal to the multiple values of the font size. For example,

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()

The resulting plot is:

enter image description here

like image 105
swatchai Avatar answered Mar 28 '23 00:03

swatchai