Package igraph :: Module colors :: Class Palette
[hide private]
[frames] | no frames]

Class Palette

object --+
         |
        Palette
Known Subclasses:

Base class of color palettes.

Color palettes are mappings that assign integers from the range 0..n-1 to colors (3-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]
 
__getitem__(self, v)
Returns the given color from the palette.
 
__init__(self, n)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__len__(self)
 
_get(self, v)
Override this method in a subclass to create a custom palette.
 
_get_length(self)
 
clear_cache(self)
Clears the result cache.
 
get(self, v)
Returns the given color from the palette.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]
  length

Inherited from object: __class__

Method Details [hide private]

__getitem__(self, v)
(Indexing operator)

 

Returns the given color 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:
  • v - the color to be retrieved. If it is an integer, it is passed to Palette._get to be translated to an RGB triplet. Otherwise it is passed to color_name_to_rgb() to determine the RGB values.
Returns:
the color as an RGB triplet

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 RGB triplets, 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.

__init__(self, n)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

_get(self, v)

 

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 3-tuple containing the RGB values

clear_cache(self)

 

Clears the result cache.

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

get(self, v)

 

Returns the given color 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:
  • v - the color to be retrieved. If it is an integer, it is passed to Palette._get to be translated to an RGB triplet. Otherwise it is passed to color_name_to_rgb() to determine the RGB values.
Returns:
the color as an RGB triplet

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 RGB triplets, 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.


Property Details [hide private]

length

Get Method:
_get_length(self)
Set Method:
'the length of the palette'