Hi all,

I'm relatively new to matplotlib but have been generating some plots  
without too much trouble over the last couple of weeks. Now I'm  
getting trickier...

I have a timeseries plot that plots a few values against an x-axis of  
dates. I *really* want to have my key line change color to red when  
the values are *critical* but am having no success working with the  
examples I can find. It appears that with dates as an x-axis,  
something else needs to happen.

Here is the code:

# prep for multicolored line  <-- here I simply generate the list of  
required color values
r = colorConverter.to_rgba('r')
b = colorConverter.to_rgba('black')
color = list()
for f in daily_fvfm:
   if f <= -0.4:
     color.append(r)
   else:
     color.append(b)


# create the linecollection
points = zip(date_range, daily_fvfm)
segments = zip(points[:-1], points[1:])
lc = LineCollection(segments, colors = color)   <--- here is where I  
get the error at run-time (see below)


# create a figure with two subplots and add a
# second axis to the first figure

fig = mpl.figure(1)
fig.set_size_inches((10,5))
ax1 = fig.add_subplot(211)
ax2 = ax1.twinx()

ax3 = fig.add_subplot(212)

# plot the sst and then the par
ax1.plot(date_range[start_index:end_index],  
daily_sst[start_index:end_index], 'b-')
ax1.plot(date_range[start_index:end_index],  
daily_par[start_index:end_index], color='darkgoldenrod')

# then plot Fv/Fm
#ax2.plot(date_range[start_index:end_index],  
daily_fvfm[start_index:end_index], lw='2', color='black')
ax2.add_collection(lc)

Traceback (most recent call last):
   File "plot.py", line 87, in <module>
     lc = LineCollection(segments, colors = color)
   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
python2.6/site-packages/matplotlib/collections.py", line 926, in  
__init__
     self.set_segments(segments)
   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
python2.6/site-packages/matplotlib/collections.py", line 938, in  
set_segments
     seg = np.asarray(seg, np.float_)
   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
python2.6/site-packages/numpy/core/numeric.py", line 230, in asarray
     return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.

Can a multicolor line be done with dates. if so, what is the  
manipulation I need to do for dates?


Tim Burgess


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to