sarbjit
sarbjit

Reputation: 3914

Modifying attributes of plotted lines in Matplotlib

I have plotted two arrays using Matplotlib stem command as follow:

markerline, stemlines, baseline = stem(n,x,linefmt='b')
axis([0,6,0,1.2])
grid()
setp(stemlines, 'linewidth','2.0')

Now i want to modify the color of the stemlines, so i tried the following syntax but it gave me error.

setp(stemlines, 'linfmt','b-')
setp(stemlines, 'color','b-')

Is there a way i can modify the color or other attributes of these lines in general without have to specify them at the time of instantiation (i.e. using stem command)

Upvotes: 2

Views: 1123

Answers (1)

joaquin
joaquin

Reputation: 85683

You must use only a color key. You are using a color+line-type

setp(stemlines, 'color', 'b')

Note you can use either matlab or python style, although I prefer the python one:

>>> setp(stemlines, 'linewidth', 2, 'color', 'r')  # MATLAB style

>>> setp(stemlines, linewidth=2, color='r')       # python style

You can also modify your lines one by one taking them from the stemlines list. For example:

for line in stemlines:
     line.set_color('r') 

Upvotes: 3

Related Questions