python-igraph manual

For using igraph from Python

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

Module colors

source code

Color handling functions.


License: Copyright (C) 2006-2012 Tamás Nepusz <ntamas@gmail.com> Pázmány Péter sétány 1/a, 1117 Budapest, Hungary This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Classes [hide private]
  Palette
Base class of color palettes.
  GradientPalette
Base class for gradient palettes
  AdvancedGradientPalette
Advanced gradient that consists of more than two base colors.
  RainbowPalette
A palette that varies the hue of the colors along a scale.
  PrecalculatedPalette
A palette that returns colors from a pre-calculated list of colors
  ClusterColoringPalette
A palette suitable for coloring vertices when plotting a clustering.
Functions [hide private]
 
clamp(value, min_value, max_value)
Clamps the given value between min and max
source code
 
color_name_to_rgb(color, palette=None)
Converts a color given in one of the supported color formats to R-G-B values.
source code
 
color_name_to_rgba(color, palette=None)
Converts a color given in one of the supported color formats to R-G-B-A values.
source code
 
color_to_html_format(color)
Formats a color given as a 3-tuple or 4-tuple in HTML format.
source code
 
darken(color, ratio=0.5)
Creates a darker version of a color given by an RGB triplet.
source code
 
hsla_to_rgba(h, s, l, alpha=1.0)
Converts a color given by its HSLA coordinates (hue, saturation, lightness, alpha) to RGBA coordinates.
source code
 
hsl_to_rgb(h, s, l)
Converts a color given by its HSL coordinates (hue, saturation, lightness) to RGB coordinates.
source code
 
hsva_to_rgba(h, s, v, alpha=1.0)
Converts a color given by its HSVA coordinates (hue, saturation, value, alpha) to RGB coordinates.
source code
 
hsv_to_rgb(h, s, v)
Converts a color given by its HSV coordinates (hue, saturation, value) to RGB coordinates.
source code
 
rgba_to_hsla(r, g, b, alpha=1.0)
Converts a color given by its RGBA coordinates to HSLA coordinates (hue, saturation, lightness, alpha).
source code
 
rgba_to_hsva(r, g, b, alpha=1.0)
Converts a color given by its RGBA coordinates to HSVA coordinates (hue, saturation, value, alpha).
source code
 
rgb_to_hsl(r, g, b)
Converts a color given by its RGB coordinates to HSL coordinates (hue, saturation, lightness).
source code
 
rgb_to_hsv(r, g, b)
Converts a color given by its RGB coordinates to HSV coordinates (hue, saturation, value).
source code
 
lighten(color, ratio=0.5)
Creates a lighter version of a color given by an RGB triplet.
source code
Variables [hide private]
  known_colors = {'alice blue': (0.941176470588, 0.972549019608,...
  palettes = {'gray': <GradientPalette with 256 colors>, 'heat':...
  __package__ = 'igraph.drawing'

Imports: Matrix, str_to_orientation, ceil


Function Details [hide private]

color_name_to_rgb(color, palette=None)

source code 

Converts a color given in one of the supported color formats to R-G-B values.

This is done by calling color_name_to_rgba and then throwing away the alpha value.

See Also: color_name_to_rgba for more details about what formats are understood by this function.

color_name_to_rgba(color, palette=None)

source code 

Converts a color given in one of the supported color formats to R-G-B-A values.

Examples:

>>> color_name_to_rgba("red")
(1.0, 0.0, 0.0, 1.0)
>>> color_name_to_rgba("#ff8000") == (1.0, 128/255.0, 0.0, 1.0)
True
>>> color_name_to_rgba("#ff800080") == (1.0, 128/255.0, 0.0, 128/255.0)
True
>>> color_name_to_rgba("#08f") == (0.0, 136/255.0, 1.0, 1.0)
True
>>> color_name_to_rgba("rgb(100%, 50%, 0%)")
(1.0, 0.5, 0.0, 1.0)
>>> color_name_to_rgba("rgba(100%, 50%, 0%, 25%)")
(1.0, 0.5, 0.0, 0.25)
>>> color_name_to_rgba("hsla(120, 100%, 50%, 0.5)")
(0.0, 1.0, 0.0, 0.5)
>>> color_name_to_rgba("hsl(60, 100%, 50%)")
(1.0, 1.0, 0.0, 1.0)
>>> color_name_to_rgba("hsv(60, 100%, 100%)")
(1.0, 1.0, 0.0, 1.0)
Parameters:
  • color - the color to be converted in one of the following formats:
    • CSS3 color specification: #rrggbb, #rgb, #rrggbbaa, #rgba, rgb(red, green, blue), rgba(red, green, blue, alpha), hsl(hue, saturation, lightness), hsla(hue, saturation, lightness, alpha), hsv(hue, saturation, value) and hsva(hue, saturation, value, alpha) where the components are given as hexadecimal numbers in the first four cases and as decimals or percentages (0%-100%) in the remaining cases. Red, green and blue components are between 0 and 255; hue is between 0 and 360; saturation, lightness and value is between 0 and 100; alpha is between 0 and 1.
    • Valid HTML color names, i.e. those that are present in the HTML 4.0 specification
    • Valid X11 color names, see http://en.wikipedia.org/wiki/X11_color_names
    • Red-green-blue components given separately in either a comma-, slash- or whitespace-separated string or a list or a tuple, in the range of 0-255. An alpha value of 255 (maximal opacity) will be assumed.
    • Red-green-blue-alpha components given separately in either a comma-, slash- or whitespace-separated string or a list or a tuple, in the range of 0-255
    • A single palette index given either as a string or a number. Uses the palette given in the palette parameter of the method call.
  • palette - the palette to be used if a single number is passed to the method. Must be an instance of colors.Palette.
Returns:
the RGBA values corresponding to the given color in a 4-tuple. Since these colors are primarily used by Cairo routines, the tuples contain floats in the range 0.0-1.0

color_to_html_format(color)

source code 

Formats a color given as a 3-tuple or 4-tuple in HTML format.

The HTML format is simply given by #rrggbbaa, where rr gives the red component in hexadecimal format, gg gives the green component bb gives the blue component and gg gives the alpha level. The alpha level is optional.

darken(color, ratio=0.5)

source code 

Creates a darker version of a color given by an RGB triplet.

This is done by mixing the original color with black using the given ratio. A ratio of 1.0 will yield a completely black color, a ratio of 0.0 will yield the original color. The alpha values are left intact.

hsla_to_rgba(h, s, l, alpha=1.0)

source code 

Converts a color given by its HSLA coordinates (hue, saturation, lightness, alpha) to RGBA coordinates.

Each of the HSLA coordinates must be in the range [0, 1].

hsl_to_rgb(h, s, l)

source code 

Converts a color given by its HSL coordinates (hue, saturation, lightness) to RGB coordinates.

Each of the HSL coordinates must be in the range [0, 1].

hsva_to_rgba(h, s, v, alpha=1.0)

source code 

Converts a color given by its HSVA coordinates (hue, saturation, value, alpha) to RGB coordinates.

Each of the HSVA coordinates must be in the range [0, 1].

hsv_to_rgb(h, s, v)

source code 

Converts a color given by its HSV coordinates (hue, saturation, value) to RGB coordinates.

Each of the HSV coordinates must be in the range [0, 1].

rgba_to_hsla(r, g, b, alpha=1.0)

source code 

Converts a color given by its RGBA coordinates to HSLA coordinates (hue, saturation, lightness, alpha).

Each of the RGBA coordinates must be in the range [0, 1].

rgba_to_hsva(r, g, b, alpha=1.0)

source code 

Converts a color given by its RGBA coordinates to HSVA coordinates (hue, saturation, value, alpha).

Each of the RGBA coordinates must be in the range [0, 1].

rgb_to_hsl(r, g, b)

source code 

Converts a color given by its RGB coordinates to HSL coordinates (hue, saturation, lightness).

Each of the RGB coordinates must be in the range [0, 1].

rgb_to_hsv(r, g, b)

source code 

Converts a color given by its RGB coordinates to HSV coordinates (hue, saturation, value).

Each of the RGB coordinates must be in the range [0, 1].

lighten(color, ratio=0.5)

source code 

Creates a lighter version of a color given by an RGB triplet.

This is done by mixing the original color with white using the given ratio. A ratio of 1.0 will yield a completely white color, a ratio of 0.0 will yield the original color.


Variables Details [hide private]

known_colors

Value:
{'alice blue': (0.941176470588, 0.972549019608, 1.0, 1.0),
 'aliceblue': (0.941176470588, 0.972549019608, 1.0, 1.0),
 'antique white': (0.980392156863,
                   0.921568627451,
                   0.843137254902,
                   1.0),
 'antiquewhite': (0.980392156863, 0.921568627451, 0.843137254902, 1.0)\
,
...

palettes

Value:
{'gray': <GradientPalette with 256 colors>,
 'heat': <AdvancedGradientPalette with 256 colors>,
 'rainbow': <RainbowPalette with 256 colors>,
 'red-black-green': <AdvancedGradientPalette with 256 colors>,
 'red-blue': <GradientPalette with 256 colors>,
 'red-green': <GradientPalette with 256 colors>,
 'red-purple-blue': <AdvancedGradientPalette with 256 colors>,
 'red-yellow-green': <AdvancedGradientPalette with 256 colors>,
...

   Home       Trees       Indices       Help