传说中的多个标记 [英] multiple markers in legend

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

问题描述

我的绘图脚本会为每个标签创建两个图例。我不知道如何使legend()不重复。我检查了stackoverflow并发现了两种方法。但我无法在这里实施。有任何想法吗?



plt.legend doc 图例 doc


My script for plotting creates two legends for each label. I do not know how to make legend() not duplicate. I checked on stackoverflow and found two methods. But I could not implement them here. Any ideas?

Matplotlib: Don't show errorbars in legend

Stop matplotlib repeating labels in legend

symbols = [u'\u2193']
#Plotting our vsini values
for i, symbol in enumerate(symbols):
    for x0,y0 in zip(vsini_slit_cl, vsini_slit):
        plt.text(x0,y0, symbol, fontname='STIXGeneral', size = 10, va='center', ha='center', clip_on=True,color = '#737373')
for i, symbol in enumerate(symbols):
    for x0, y0 in zip(vsini_cl_sl, vsini_sl):
       plt.text(x0, y0, symbol, fontname='STIXGeneral', size = 10, va='center', ha='center', clip_on=True)

# PLOTTING VSINI FROM LITERATURE 
plt.plot((vmag_lit-jmag_lit), vsini_lit, 'o', color = '#a6a6a6', label='Literature')
# PLOTTING SLOW VSINI FROM LITERATURE 
plt.plot(vsini_slit_cl, vsini_slit, 'o', color = '#a6a6a6')
# PLOTTING VSINI FROM OUR WORK
plt.plot(vsini_cl_sl, vsini_sl, 'o', label='This Work' )
plt.errorbar(vsini_color, vsini_chad, yerr=vsini_chad_sig, fmt='bo', capsize=3)
plt.legend()        
plt.savefig('vsini_colors.jpg', dpi=200)

解决方案

Just use

plt.legend(numpoints=1)

The default behavior is to use 2 points, which is what you need to make a legend entry for lines.

See: legend user guide and plt.legend doc and legend doc

这篇关于传说中的多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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