简体   繁体   中英

Text in legend for matplotlib plot

I have a plot and want a legend placed in the upper right corner without any frame around with two lines:

a = 10
b = 3*pi

Those lines are some coefficients of my plotted function.

So far, I have

ax1.plot(x, y, label='a')
ax1.legend(["a = 10", "b = 3*pi"], loc="upper right", ncol=1, frameon=False)

But that keeps lines type or color next to my two strings. How to remove them? Put it in the title is not an option. There is a different text.

Use the text method of the axes object. Also, remember that the default is that the first 2 arguments of ax1.text are in data coordinates , so in your example, Hello will be put at (x,y)=(.6, .06) , unless you also add the parameter transform=ax1.transAxes to ax1.text , like so:

ax1.text(.60, .06, r'Hello', transform=ax1.transAxes)

That will add the text label a little over halfway from the left and a little higher than the bottom of the axes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM