matplotlib.artist.setp#
- matplotlib.artist.setp(obj, *args, file=None, **kwargs)[source]#
设置一个或多个
Artist(美工对象)的属性,或列出允许的值。- 参数:
- obj
Artist或Artist列表 正在设置或查询其属性的 artist(美工对象)。在设置属性时,所有 artist 都会受到影响;在查询允许的值时,仅查询序列中的第一个实例。
例如,可以通过单次调用将两条线同时加粗并设为红色
>>> x = arange(0, 1, 0.01) >>> lines = plot(x, sin(2*pi*x), x, sin(4*pi*x)) >>> setp(lines, linewidth=2, color='r')
- file类文件对象,默认值:
sys.stdout 当要求列出允许的值时,
setp输出写入的目标位置。>>> with open('output.log') as file: ... setp(line, file=file)
默认值
None表示sys.stdout。- *args, **kwargs
要设置的属性。支持以下组合:
将线条的线型设置为虚线
>>> line, = plot([1, 2, 3]) >>> setp(line, linestyle='--')
同时设置多个属性
>>> setp(line, linewidth=2, color='r')
列出线条线型的允许值
>>> setp(line, 'linestyle') linestyle: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
列出所有可设置的属性及其允许的值
>>> setp(line) agg_filter: a filter function, ... [long output listing omitted]
setp也支持 MATLAB 风格的字符串/值对。例如,以下写法是等效的>>> setp(lines, 'linewidth', 2, 'color', 'r') # MATLAB style >>> setp(lines, linewidth=2, color='r') # Python style
- obj
另请参阅