matplotlib 多条线注释

2 投票
1 回答
5842 浏览
提问于 2025-04-18 05:51

在matplotlib中,能不能显示一个多行的注释呢?

这是一个单行注释:

ax.annotate('line1', xy=(xi,yi),  xycoords='data',
                    xytext=(-50, 30), textcoords='offset points',
                    arrowprops=dict(arrowstyle="->")
                    )

这是我想要做的(这个是通过图形界面编辑的):

在这里输入图片描述

1 个回答

5

其实很简单,只需要在一行的末尾加上“\n”就可以了:

'line1 \n line2 \n line3'

ax.annotate('line1 \n line2', xy=(timeNow, y),  xycoords='data',
            xytext=(-50, 30), textcoords='offset points',
            arrowprops=dict(arrowstyle="->"),
            verticalalignment='center', 
            horizontalalignment='center'
            )

撰写回答