Re: [Matplotlib-users] legend not covering graphs

You can call legend as follows:

plt.legend(loc=0)

and it will place the legend where it obscures as little as possible.

Is this the same as loc='best'?
I actually need to make extra space for the legend. I guess this can
only be done manually?

···

On Tue, Feb 16, 2021 at 12:13 PM swfiua@gmail.com <swfiua@gmail.com> wrote:

You can call legend as follows:

plt.legend(loc=0)

and it will place the legend where it obscures as little as possible.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@python.org
Matplotlib-users Info Page

--
Those who don't understand recursion are doomed to repeat it
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

You can use the “loc” argument in combination with “bbox_to_anchor”. Not sure if you call this “manual” or “automatic” but the width of the legend is adjusted automatically and it can be placed outside the axes:

plt.figure()
plt.plot([1,3,2], label='first')
plt.plot([2,1,5], label='second')
plt.legend(loc='upper left', bbox_to_anchor=(1,1))

mfoheigkgccdhaao.png

plt.figure()
plt.plot([1,3,2], label='first')
plt.plot([2,1,5], label='a very wide legend')
plt.legend(loc='upper left', bbox_to_anchor=(1,1))

jgolmngggkmcpohh.png

Regards,
Johann

The integrity and confidentiality of this e-mail is governed by these terms / Die integriteit en vertroulikheid van hierdie e-pos word deur die volgende bepalings gereël. http://www.sun.ac.za/emaildisclaimer

···

On 16/02/2021 19:56, Neal Becker wrote:

Is this the same as loc='best'?
I actually need to make extra space for the legend.  I guess this can
only be done manually?

On Tue, Feb 16, 2021 at 12:13 PM   wrote:

swfiua@gmail.comswfiua@gmail.com

You can call legend as follows:

plt.legend(loc=0)

and it will place the legend where it obscures as little as possible.
_______________________________________________
Matplotlib-users mailing list

Matplotlib-users@python.orghttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fmatplotlib-users&data=04%7C01%7C%7C3e608a9c59244760240a08d8d2a4530f%7Ca6fa3b030a3c42588433a120dffcd348%7C0%7C0%7C637490950547351116%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=a1T%2Bs3qJVGwEEYT1jNv9THkj2Jj8nQzUT0VQv%2BHidxU%3D&reserved=0


--
Those who don't understand recursion are doomed to repeat it
_______________________________________________
Matplotlib-users mailing list

Matplotlib-users@python.orghttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fmatplotlib-users&data=04%7C01%7C%7C3e608a9c59244760240a08d8d2a4530f%7Ca6fa3b030a3c42588433a120dffcd348%7C0%7C0%7C637490950547351116%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=a1T%2Bs3qJVGwEEYT1jNv9THkj2Jj8nQzUT0VQv%2BHidxU%3D&reserved=0