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
If you want to plot a Pandas dataframe and want to remove the legend, add legend=None as parameter to the plot command.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df2 = pd.DataFrame(np.random.randn(10, 5))
df2.plot(legend=None)
plt.show()
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.