4

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)

enter image description here

Community
  • 1
  • 1
Rohit
  • 5,840
  • 13
  • 42
  • 65
  • Can you change the title to something like 'multiple markers in legend'? The title now makes me think more of the line 'This work' showing up a bunch of times. – tacaswell Jun 01 '13 at 20:11

1 Answers1

4

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

tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • Along these lines, I wanted to know why the "downward arrows" appear in front of the filled circles even when I plot the arrows first and then then filled circles? – Rohit Jun 01 '13 at 20:15
  • 1
    the answer is specify a 'zorder'. http://stackoverflow.com/questions/16770049/strange-matplotlib-zorder-behavior-with-legend-and-errorbar – tacaswell Jun 01 '13 at 20:22
  • Thanks for everything and for a quick reply! Very much appreciated. I really like working in Python. Gives you a lot of freedom than IDL. – Rohit Jun 01 '13 at 20:39