Search code examples
pythonmatplotlibhistogram

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!


Solution

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

    plt.legend()