Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python matplotlib: label in histogram

I am using Python (3.4) Jupyter Notebook. I tried to plot a histogram with label using the code below.

   %matplotlib notebook
    import matplotlib.pyplot as plt
    import matplotlib
    import numpy as np

    bins = np.linspace(0, 1.0, 40)

    plt.hist(good_tests, bins, alpha = 0.5, color = 'b' , label = 'good')
    plt.show()

But the label 'good' doesn't show at all. Did I miss anything? Thanks!

like image 696
Edamame Avatar asked Dec 05 '22 16:12

Edamame


1 Answers

you need to add a legend. See legend for details.

plt.legend()
like image 181
Stian Avatar answered Jan 05 '23 02:01

Stian