setting line parameters like color, lw, etc

Hello everyone,

Newbie alert.

How do I set the attributes of Line2D instance? I have:

  origline = plt.plot(origlist)
  valine = plt.plot(valist)
  plt.xlim(0,256)
  valine.set_color('r')
  valine.set_linewidth(2)

I get:

Traceback (most recent call last):
   File "C:/Python26/loadavg2.py", line 121, in <module>
     plotit(valist, smalist)
   File "C:/Python26/loadavg2.py", line 106, in plotit
     valine.set_color('r')
AttributeError: 'list' object has no attribute 'set_color'

WTF?? After all, Line2D api docs, e.g.

http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.lines.Line2D.set_color

clearly state there is set_color method to the Line2D instance!

I get the same error with get_* methods.

Regards,
mk

As mentioned in the traceback, valine is a list and not a Line2D
instance. In fact, the plt.plot function returns the list of the Line2D
instances added to the axes by the instruction. Even if you only plot
one curve.
As a solution, you may correct to
        valine, = plt.plot(valist)
which unpack the list and extract the first item (the Line2D instance
you want) to valine.

···

Le mardi 27 janvier 2009 à 13:17 +0100, Marcin Krol a écrit :

How do I set the attributes of Line2D instance? I have:

  origline = plt.plot(origlist)
  valine = plt.plot(valist)
  plt.xlim(0,256)
  valine.set_color('r')
  valine.set_linewidth(2)

Traceback (most recent call last):
AttributeError: 'list' object has no attribute 'set_color'

--
Fabrice Silva <silva@...1918...>
LMA UPR CNRS 7051 - équipe S2M