multiple markers in legend

柔情痞子 提交于 2020-01-03 15:33:36

问题


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)


回答1:


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



来源:https://stackoverflow.com/questions/16876396/multiple-markers-in-legend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!