On Thu, May 1, 2008 at 4:32 PM, Michael Hearne <[EMAIL PROTECTED]> wrote:
>  legend(('s1','s2'))
>
>  The resulting legend shows the symbols twice (two little red dots and
>  two blue ones).  Does anyone else get this, and if so, do you know
>  what the problem is?

You can tell the legend how many points to draw using the numpoints
kwarg.  See the docs at
http://matplotlib.sourceforge.net/matplotlib.legend.html#Legend

Check out the example code below -- in addition tomaking the numpoints
setting, it also fixes the tick format overlap problem

import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mpldates
import matplotlib.ticker as ticker

date1 = datetime.date( 1952, 1, 1 )
date2 = datetime.date( 2004, 4, 12 )
delta = datetime.timedelta(days=100)
dates = mpldates.drange(date1, date2, delta)
s1 = np.random.rand(len(dates))

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot_date(dates, s1,'r.')
ax.hold(True)
s2 = np.random.rand(len(dates))
ax.plot_date(dates, s2,'bo')
ax.legend(('s1','s2'), numpoints=1)

# only write ticklabels on the decades
def fmtticks(x, pos=None):
    dt = mpldates.num2date(x)
    if dt.year%10: return ''
    return dt.strftime('%Y')

# this fizes yhe tick labels
ax.xaxis.set_major_formatter(ticker.FuncFormatter(fmtticks))

# this fixes the toolbar x coord
ax.fmt_xdata = mpldates.DateFormatter('%Y-%m-%d')

# this rotates the ticklabels to help with overlapping
fig.autofmt_xdate()
plt.show()

JDH

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to