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'
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.
--
Fabrice Silva <si...@lm...>
LMA UPR CNRS 7051 - équipe S2M
|