Unable to show legend in seaborn distplot

前端 未结 3 995
猫巷女王i
猫巷女王i 2021-02-06 21:31

I am new to plotting in python and trying following code to plot distribution in seaborn but unable to see the legend, i.e., test_label1 and test

3条回答
  •  遇见更好的自我
    2021-02-06 22:11

    By using fig.legend we can show legends in the distribution plot. Here, an argument array of labels is passed to the function. Labels in the legend will also be displayed as an order of array values.

    import seaborn as sns
    import matplotlib.pyplot as plt
    
    fig = plt.figure(figsize=(10,6))
    lst1 = list(np.random.rand(10))
    lst2 = list(np.random.rand(10))
    sns.distplot(lst1)
    sns.distplot(lst1)
    fig.legend(labels=['test_label1','test_label2'])
    plt.show()
    

提交回复
热议问题