class Palette:
Known subclasses: igraph.drawing.colors.AdvancedGradientPalette
, igraph.drawing.colors.GradientPalette
, igraph.drawing.colors.PrecalculatedPalette
, igraph.drawing.colors.RainbowPalette
Base class of color palettes.
Color palettes are mappings that assign integers from the range 0..n − 1 to colors (4-tuples). n is called the size or length of the palette. igraph comes with a number of predefined palettes, so this class is useful for you only if you want to define your own palette. This can be done by subclassing this class and implementing the Palette._get
method as necessary.
Palettes can also be used as lists or dicts, for the __getitem__ method is overridden properly to call Palette.get
.
Method | __init__ |
Undocumented |
Method | __len__ |
Returns the number of colors in this palette |
Method | __plot__ |
Plots the colors of the palette on the given Cairo context |
Method | __repr__ |
Undocumented |
Method | clear |
Clears the result cache. |
Method | get |
Returns the given color from the palette. |
Method | get |
Returns multiple colors from the palette. |
Property | length |
Returns the number of colors in this palette |
Method | _get |
Override this method in a subclass to create a custom palette. |
Instance Variable | _cache |
Undocumented |
Instance Variable | _length |
Undocumented |
Plots the colors of the palette on the given Cairo context
Supported keyword arguments are:
- 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.
- 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.
Clears the result cache.
The return values of Palette.get
are cached. Use this method to clear the cache.
Returns the given color from the palette.
Values are cached: if the specific value given has already been looked up, its value will be returned from the cache instead of calculating it again. Use Palette.clear_cache
to clear the cache if necessary.
Parameters | |
v | the color to be retrieved. If it is an integer, it is passed to Palette._get to be translated to an RGBA quadruplet. Otherwise it is passed to color_name_to_rgb() to determine the RGBA values. |
Returns | |
the color as an RGBA quadruplet | |
Note | |
you shouldn't override this method in subclasses, override _get instead. If you override this method, lookups in the known_colors dict won't work, so you won't be able to refer to colors by names or RGBA quadruplets, only by integer indices. The caching functionality will disappear as well. However, feel free to override this method if this is exactly the behaviour you want. |
Returns multiple colors from the palette.
Values are cached: if the specific value given has already been looked upon, its value will be returned from the cache instead of calculating it again. Use Palette.clear_cache
to clear the cache if necessary.
Parameters | |
colors | the list of colors to be retrieved. The palette class tries to make an educated guess here: if it is not possible to interpret the value you passed here as a list of colors, the class will simply try to interpret it as a single color by forwarding the value to Palette.get . |
Returns | |
the colors as a list of RGBA quadruplets. The result will be a list even if you passed a single color index or color name. |
igraph.drawing.colors.AdvancedGradientPalette
, igraph.drawing.colors.GradientPalette
, igraph.drawing.colors.PrecalculatedPalette
, igraph.drawing.colors.RainbowPalette
Override this method in a subclass to create a custom palette.
You can safely assume that v is an integer in the range 0..n − 1 where n is the size of the palette.
Parameters | |
v | numerical index of the color to be retrieved |
Returns | |
a 4-tuple containing the RGBA values |