python matplotlib:直方图中的标签 [英] python matplotlib: label in histogram

查看:625
本文介绍了python matplotlib:直方图中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!

推荐答案

您需要添加图例.有关详细信息,请参见传奇.

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

plt.legend()

这篇关于python matplotlib:直方图中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆