Remove or adapt the border of the legend frame using matplotlib

When plotting using matplotlib:

  • How to remove a legend field?
  • How to change the border color of a legend window?
  • How to remove only the legend window frame?
+51
python matplotlib
Aug 28 '14 at 3:29
source share
2 answers

When plotting using matplotlib:

How to remove a legend field?

plt.legend(frameon=False) 

How to change the border color of a legend window?

 leg = plt.legend() leg.get_frame().set_edgecolor('b') 

How to remove only the legend window frame?

 leg = plt.legend() leg.get_frame().set_linewidth(0.0) 
+94
Aug 28 '14 at 3:31 on
source share
— -

Another related question, since it took forever to find the answer:

How to make the background image of a legend empty (i.e. transparent, not white):

 legend = plt.legend() legend.get_frame().set_facecolor('none') 

Warning, you want 'none' (string). None means the default color.

+9
Nov 11 '16 at 4:51 on
source share



All Articles