📌  相关文章
📜  Python中的 Matplotlib.axes.Axes.set_prop_cycle()

📅  最后修改于: 2022-05-13 01:55:27.434000             🧑  作者: Mango

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()函数用于设置轴的属性循环。

下面的示例说明了 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()

输出: