python matplotlib: label in histogram

痞子三分冷 提交于 2019-12-30 10:32:28

问题


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!


回答1:


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

plt.legend()


来源:https://stackoverflow.com/questions/41213346/python-matplotlib-label-in-histogram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!