python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Package drawing :: Module colors :: Class Palette
[hide private]

Class Palette

source code

object --+
         |
        Palette
Known Subclasses:

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.

Instance Methods [hide private]
 
__init__(self, n)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
clear_cache(self)
Clears the result cache.
source code
 
get(self, v)
Returns the given color from the palette.
source code
 
get_many(self, colors)
Returns multiple colors from the palette.
source code
 
_get(self, v)
Override this method in a subclass to create a custom palette.
source code
 
__getitem__(self, v)
Returns the given color from the palette.
source code
 
__len__(self)
Returns the number of colors in this palette
source code
 
__plot__(self, context, bbox, palette, *args, **kwds)
Plots the colors of the palette on the given Cairo context
source code
 
__repr__(self)
repr(x)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  length
Returns the number of colors in this palette

Inherited from object: __class__

Method Details [hide private]

__init__(self, n)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

clear_cache(self)

source code 

Clears the result cache.

The return values of Palette.get are cached. Use this method to clear the cache.

get(self, v)

source code 

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.

get_many(self, colors)

source code 

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.

_get(self, v)

source code 

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

__getitem__(self, v)
(Indexing operator)

source code 

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.

__plot__(self, context, bbox, palette, *args, **kwds)

source code 

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.

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

Property Details [hide private]

length

Returns the number of colors in this palette

Get Method:
unreachable.length(self) - Returns the number of colors in this palette

   Home       Trees       Indices       Help