class documentation

颜色调色板的基类。

调色板是将0到n − 1范围内的整数映射到颜色(四元组)的映射。n被称为调色板的大小或长度。igraph附带了许多预定义的调色板,因此只有在您想定义自己的调色板时,这个类才对您有用。这可以通过子类化这个类并根据需要实现Palette._get方法来完成。

调色板也可以用作列表或字典,因为__getitem__方法被正确重写以调用Palette.get

方法 __init__ 未记录
方法 __len__ 返回此调色板中的颜色数量
方法 __plot__ 在给定的Cairo上下文/mpl Axes上绘制调色板的颜色
方法 __repr__ 未记录
方法 clear_cache 清除结果缓存。
方法 get 从调色板中返回给定的颜色。
方法 get_many 从调色板返回多种颜色。
属性 length 返回此调色板中的颜色数量
方法 _get 在子类中重写此方法以创建自定义调色板。
实例变量 _cache 未记录
实例变量 _length 未记录
def __len__(self): (source)

返回此调色板中的颜色数量

def __plot__(self, backend, context, *args, **kwds): (source)

在给定的Cairo上下文/mpl Axes上绘制调色板的颜色

在Cairo和matplotlib中支持的关键字参数有:

  • orientation: the orientation of the palette. Must be one of the following values: left-right, bottom-top, right-left or top-bottom. Possible aliases: horizontal = left-right, vertical = bottom-top, lr = left-right, rl = right-left, tb = top-bottom, bt = bottom-top. The default is left-right.

在Cairo中额外支持的关键字参数有:

  • border_width: line width of the border shown around the palette. If zero or negative, the border is turned off. Default is 1.
  • grid_width: line width of the grid that separates palette cells. If zero or negative, the grid is turned off. The grid is also turned off if the size of a cell is less than three times the given line width. Default is 0. Fractional widths are also allowed.

matplotlib中的关键字参数传递给Axes.imshow。

def __repr__(self): (source)

未记录

def clear_cache(self): (source)

清除结果缓存。

Palette.get 的返回值会被缓存。使用此方法来清除缓存。

def get(self, v): (source)

从调色板返回给定的颜色。

值会被缓存:如果给定的特定值已经被查找过,它的值将从缓存中返回,而不是再次计算。如果需要,使用Palette.clear_cache来清除缓存。

参数
v要检索的颜色。如果它是一个整数,它将被传递给Palette._get以转换为RGBA四元组。否则,它将被传递给color_name_to_rgb()以确定RGBA值。
返回
颜色作为RGBA四元组
注意
你不应该在子类中重写这个方法,而是重写_get。如果你重写了这个方法,known_colors字典中的查找将无法工作,因此你将无法通过名称或RGBA四元组引用颜色,只能通过整数索引引用。缓存功能也将消失。然而,如果这正是你想要的行为,请随意重写这个方法。
def get_many(self, colors): (source)

从调色板返回多种颜色。

值会被缓存:如果给定的特定值已经被查找过,它的值将从缓存中返回,而不是重新计算。如果需要,使用Palette.clear_cache来清除缓存。

参数
colors要检索的颜色列表。调色板类会尝试在这里做出合理的猜测:如果无法将您传递的值解释为颜色列表,该类将尝试通过将值转发到Palette.get来解释为单一颜色。
返回
颜色作为RGBA四元组的列表。即使你传递了单个颜色索引或颜色名称,结果也将是一个列表。

返回此调色板中的颜色数量

@abstractmethod
def _get(self, v): (source)

在子类中重写此方法以创建自定义调色板。

你可以安全地假设v是一个在0到n − 1范围内的整数,其中n是调色板的大小。

参数
v要检索的颜色的数值索引
返回
一个包含RGBA值的4元组

未记录

未记录