【问题标题】:matplotlib histograms and labelsmatplotlib 直方图和标签
【发布时间】:2013-06-06 09:27:32
【问题描述】:

我正在用两组数据绘制直方图,并希望包含一个键。我找到了一个使用 label 命令的示例,但是当我使用它时它不起作用。直方图显示正确,但没有键。我的代码是。

H1 = <some data>
S1 = <some other data>

hist([H1,S1], bins=25, range=(10,30), align=('mid'), color=['green', 'orange'], label=['Actual H band', 'Actual IRAC2 band'])
title("Actual observed magnitudes of sources in H and IRAC2")
xlabel("Magnitude")
ylabel("Frequency")

show()

有什么建议吗?

【问题讨论】:

    标签: matplotlib histogram


    【解决方案1】:

    您必须包含一个图例调用:

    H1 = <some data>
    S1 = <some other data>
    
    hist([H1,S1], bins=25, range=(10,30), align=('mid'), color=['green', 'orange'], label=['Actual H band', 'Actual IRAC2 band'])
    title("Actual observed magnitudes of sources in H and IRAC2")
    xlabel("Magnitude")
    ylabel("Frequency")
    legend()
    
    show()
    

    【讨论】:

    • 谢谢,我完全错过了这个例子:)
    猜你喜欢
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    相关资源
    最近更新 更多