Python 修改Matplotlib中打印线的属性
我使用Matplotlib stem命令绘制了两个阵列,如下所示:Python 修改Matplotlib中打印线的属性,python,matplotlib,Python,Matplotlib,我使用Matplotlib stem命令绘制了两个阵列,如下所示: markerline, stemlines, baseline = stem(n,x,linefmt='b') axis([0,6,0,1.2]) grid() setp(stemlines, 'linewidth','2.0') 现在我想修改stemline的颜色,所以我尝试了以下语法,但它给了我错误 setp(stemlines, 'linfmt','b-') setp(stemlines, 'color','b-')
markerline, stemlines, baseline = stem(n,x,linefmt='b')
axis([0,6,0,1.2])
grid()
setp(stemlines, 'linewidth','2.0')
现在我想修改stemline的颜色,所以我尝试了以下语法,但它给了我错误
setp(stemlines, 'linfmt','b-')
setp(stemlines, 'color','b-')
是否有一种方法可以修改这些行的颜色或其他属性,而不必在实例化时指定它们(即使用stem命令)您只能使用颜色键。您使用的是颜色+线条类型
setp(stemlines, 'color', 'b')
注意:您可以使用matlab或python样式,尽管我更喜欢python样式:
>>> setp(stemlines, 'linewidth', 2, 'color', 'r') # MATLAB style
>>> setp(stemlines, linewidth=2, color='r') # python style
也可以从stemlines列表中逐个修改行。例如:
for line in stemlines:
line.set_color('r')
在将来,可能值得包括您得到的错误。除此之外,问得好!