ipython Pandas : 为什么我不能打印 matplot 图的图例?

ipython Pandas : why I cannot print the legend for matplot graphs?

我正在使用此代码在图表上添加图例,但这是不可能的。

   for key in ['cluster0', 'cluster1', 'cluster2', 'cluster3']:
        mask = e['cluster'] == key
        ax.scatter(e['count_sbwip'][mask],e['perc_of_seen_ip'][mask],
                           c=LABEL_COLOR_MAP[key],  label=LABEL_NAMES_MAP[key])
    ax.legend()

有人可以帮忙吗?

  1. 这只是一个错字。如回溯所示,您使用参数 lebel 而不是 label 调用 ax.scatter

  2. 如果你想在同一个图上有四个图例,你可以简单地用相应的 label 参数调用 ax.scatter 4 次。我想可以手动创建这个图例,但它可能比使用类似

    的东西更复杂
    for key in ['cluster0', 'cluster1', 'cluster2', 'cluster3']:
        mask = e['cluster'] == key
        ax.scatter(e['count_sbwip'][mask],e['perc_of_seen_ip'][mask],
                           c=LABEL_COLOR_MAP[key],  label=LABEL_NAMES_MAP[key])
    ax.legend()