python matplotlib : label in histogram

标签 python matplotlib histogram

我正在使用 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()

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

最佳答案

您需要添加图例。参见 legend了解详情。

plt.legend()

关于 python matplotlib : label in histogram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41213346/

相关文章:

Pandas 直方图 df.hist() 分组方式

python - 修改Matplotlib五彩直方图脚本使其累积

python - 提高在 matplotlib 中重绘等高线图的速度

python - 如何使用Python在 basemap 中添加图例

postgresql - 使用字母值作为 x 轴在 Grafana 中创建直方图

date - D3 直方图 - 基于日期

Python3 - 如何正确地进行绝对导入并让 Pylint 开心

python - Python/C API 中 Python 胶囊的安全和防御编码视角

python - itertools.tee 是如何工作的,可以复制 'itertools.tee' 以保存它的 "status"吗?

python - Matplotlib 绘图未在 VS Code 中显示