函数功能:
Set a property on an artist object.
设置元素属性
函数语法:
setp(obj, *args, **kwargs)
函数参数:
obj: 要设置的对象
- matplotlib supports the use of setp() (“set property”) and getp() to set and get object properties, as well as to do introspection on the object.
matplotlib 支持使用setp()函数设置属性,使用getp()函数获取查看属性,以及进行自查。
例如要将线条风格设置为虚线,可以:
line, = plot([1,2,3])
setp(line, linestyle='--')
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-2*np.pi, 2 * np.pi, 200)
y = np.sin(x)
line1,=plt.plot(x,y)
plt.setp(line1,ls='--')
plt.show()
- If you want to know the valid types of arguments, you can provide the name of the property you want to set without a value:
如果您想知道参数有效的类型(可取的值),则可以提供要设置的属性名称,但不带值。
setp(line, 'linestyle')
例如:获取线条风格的取值有哪些
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-2*np.pi, 2 * np.pi, 200)
y = np.sin(x)
line,=plt.plot(x,y)
plt.setp(line,'linestyle')
运行结果
3. If you want to see all the properties that can be set, and their possible values, you can do:
如果你想要查看所有可以设置的属性和属性的取值,可以:
setp(line)
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-2*np.pi, 2 * np.pi, 200)
y = np.sin(x)
line1,=plt.plot(x,y)
plt.setp(line1)
运行结果如下:
agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
alpha: float or None
animated: bool
antialiased or aa: bool
clip_box: `.Bbox`
clip_on: bool
clip_path: Patch or (Path, Transform) or None
color or c: color
contains: unknown
dash_capstyle: {'butt', 'round', 'projecting'}
dash_joinstyle: {'miter', 'round', 'bevel'}
dashes: sequence of floats (on/off ink in points) or (None, None)
data: (2, N) array or two 1D arrays
drawstyle or ds: {'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'
figure: `.Figure`
fillstyle: {'full', 'left', 'right', 'bottom', 'top', 'none'}
gid: str
in_layout: bool
label: object
linestyle or ls: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
linewidth or lw: float
marker: marker style string, `~.path.Path` or `~.markers.MarkerStyle`
markeredgecolor or mec: color
markeredgewidth or mew: float
markerfacecolor or mfc: color
markerfacecoloralt or mfcalt: color
markersize or ms: float
markevery: None or int or (int, int) or slice or List[int] or float or (float, float) or List[bool]
path_effects: `.AbstractPathEffect`
picker: unknown
pickradius: float
rasterized: bool or None
sketch_params: (scale: float, length: float, randomness: float)
snap: bool or None
solid_capstyle: {'butt', 'round', 'projecting'}
solid_joinstyle: {'miter', 'round', 'bevel'}
transform: `matplotlib.transforms.Transform`
url: str
visible: bool
xdata: 1D array
ydata: 1D array
zorder: float
Process finished with exit code 0
官方文档: setp函数