Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the legend on a matplotlib figure

To add a legend to a matplotlib plot, one simply runs legend().

How to remove a legend from a plot?

(The closest I came to this is to run legend([]) in order to empty the legend from data. But that leaves an ugly white rectangle in the upper right corner.)

like image 636
Olivier Verdier Avatar asked Apr 20 '11 18:04

Olivier Verdier


People also ask

How do I get rid of the legend on pandas?

Using plt. gca(). legend_. remove() after the call to parallel_coordinates successfully turned off the legend.

How do I get rid of the legend border?

Therefore, we can use bty="n" with the legend function and it will remove the border of the legend.


1 Answers

As of matplotlib v1.4.0rc4, a remove method has been added to the legend object.

Usage:

ax.get_legend().remove() 

or

legend = ax.legend(...) ... legend.remove() 

See here for the commit where this was introduced.

like image 194
naitsirhc Avatar answered Oct 12 '22 22:10

naitsirhc