Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change legend edges from round to sharp corners

how can I change the edges of the frames for legends generated in matplotlib from round to having sharp corners?

like image 751
PUAaron Avatar asked Sep 16 '25 07:09

PUAaron


1 Answers

Let's use set_boxstyle:

from seaborn import load_dataset
import matplotlib.pyplot as plt

df = load_dataset('tips')

df.head()

ax = df.plot('sex',['total_bill','tip'])
ax.legend().get_frame().set_boxstyle('Round', pad=0.2, rounding_size=2)

Output:

enter image description here

like image 158
Scott Boston Avatar answered Sep 19 '25 15:09

Scott Boston