Question

Is it possible to show a multiple-line annotation in matplotlib?

This is a single line annotation:

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

This is what I need to do (this was edited graphically):

enter image description here

Was it helpful?

Solution

It was as simple as adding "\n" at the end of a line :

'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'
            )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top