简体   繁体   English

Matplotlib-使用plt.setp()使用不同的颜色

[英]Matplotlib - Different colours using plt.setp()

The matplotlib.pyplot tutorial has the following code: matplotlib.pyplot教程具有以下代码:

lines = plt.plot(x1, y1, x2, y2)
# use keyword args
plt.setp(lines, color='r', linewidth=2.0)

I'm wondering if there's anyway to specify different colours for different lines in this statement. 我想知道是否在此语句中为不同的行指定了不同的颜色。

You can specify the properties of each line with the same matplotlib.pyplot.setp() method as well: 您还可以使用相同的matplotlib.pyplot.setp()方法指定每行的属性:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.0, 0.01)
y1 = np.sin(2*np.pi*x) # function 1
y2 = np.sin(4*np.pi*x) # function 2
lines = plt.plot(x, y1, x, y2)

l1, l2 = lines # split lines     
plt.setp(l1, linewidth=1, color='r', linestyle='-') # set function 1 linestyle
plt.setp(l2, linewidth=1, color='g', linestyle='-') # set function 2 linestyle

plt.show()

Output: 输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM