python matplotlib:直方图中的标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41213346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:37:07  来源:igfitidea点击:

python matplotlib: label in histogram

pythonmatplotlibhistogram

提问by Edamame

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

我正在使用 Python (3.4) Jupyter Notebook。我尝试使用下面的代码绘制带有标签的直方图。

   %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!

但是“好”标签根本没有显示。我错过了什么吗?谢谢!

回答by Stian

you need to add a legend. See legendfor details.

你需要添加一个图例。有关详细信息,请参阅图例

plt.legend()