Remove the legend on a matplotlib figure

后端 未结 8 1148
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 19:01

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

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 19:31

    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()
    

提交回复
热议问题