Python中的 Matplotlib.axes.Axes.set_prop_cycle()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.set_prop_cycle()函数
matplotlib 库的axes 模块中的Axes.set_prop_cycle()函数用于设置轴的属性循环。
Syntax: Axes.set_prop_cycle(self, *args, **kwargs)
Parameters: This method accepts the following parameters.
- cycler : This parameter is used to set the given Cycler.
- label : This parameter is the property key.
- values : This parameter is the finite-length iterable of the property values.
Returns:This method does not returns any values.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.set_prop_cycle()函数:
示例 1:
# Implementation of matplotlib function
from cycler import cycler
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 200, 10)
yy = np.transpose([2 * np.sin(x + phi) for phi in x])
fig, ax1 = plt.subplots()
ax1.set_prop_cycle(color =['magenta', 'g',
'y', 'k'],
lw =[1, 2, 3, 4])
ax1.plot(yy)
ax1.set_title(' matplotlib.axes.Axes.set_prop_cycle() \
Example\n', fontsize = 12, fontweight ='bold')
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
from cycler import cycler
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 3 * np.pi)
offsets = np.linspace(0, 3 * np.pi, 8,
endpoint = False)
yy = np.transpose([2 * np.sin(x + phi) for phi in offsets])
plt.rc('lines', linewidth = 4)
plt.rc('axes', prop_cycle =(cycler(color =['r', 'g',
'purple',
'orange']) +
cycler(linestyle =['-',
'--',
':',
'-.'])))
fig, (ax0, ax1) = plt.subplots(nrows = 2)
ax0.plot(yy)
ax0.set_title('Above example with set_prop_cycle() \
function\n\nSet default color cycle to rgby',
fontsize = 12, fontweight ='bold')
ax1.set_prop_cycle(color =['magenta', 'g',
'y', 'k'],
lw =[1, 2, 3, 4])
ax1.plot(yy)
ax1.set_title('Set axes color cycle to cmyk',
fontsize = 12,
fontweight ='bold')
plt.show()
输出: