plotly.express.colors package¶
For a list of colors available in plotly.express.colors
, please see
Color scales are available within the following namespaces
cyclical
diverging
qualitative
sequential
-
plotly.express.colors.
color_parser
(colors, function)¶ Takes color(s) and a function and applies the function on the color(s)
In particular, this function identifies whether the given color object is an iterable or not and applies the given color-parsing function to the color or iterable of colors. If given an iterable, it will only be able to work with it if all items in the iterable are of the same type - rgb string, hex string or tuple
-
plotly.express.colors.
colorscale_to_colors
(colorscale)¶ Extracts the colors from colorscale as a list
-
plotly.express.colors.
colorscale_to_scale
(colorscale)¶ Extracts the interpolation scale values from colorscale as a list
-
plotly.express.colors.
convert_colors_to_same_type
(colors, colortype='rgb', scale=None, return_default_colors=False, num_of_defualt_colors=2)¶ Converts color(s) to the specified color type
Takes a single color or an iterable of colors, as well as a list of scale values, and outputs a 2-pair of the list of color(s) converted all to an rgb or tuple color type, aswell as the scale as the second element. If colors is a Plotly Scale name, then ‘scale’ will be forced to the scale from the respective colorscale and the colors in that colorscale will also be coverted to the selected colortype. If colors is None, then there is an option to return portion of the DEFAULT_PLOTLY_COLORS
- Parameters
colors ((str|tuple|list)) – either a plotly scale name, an rgb or hex color, a color tuple or a list/tuple of colors
scale ((list)) – see docs for validate_scale_values()
- :rtype (tuple) (colors_list, scale) if scale is None in the function call,
then scale will remain None in the returned tuple
-
plotly.express.colors.
convert_colorscale_to_rgb
(colorscale)¶ Converts the colors in a colorscale to rgb colors
A colorscale is an array of arrays, each with a numeric value as the first item and a color as the second. This function specifically is converting a colorscale with tuple colors (each coordinate between 0 and 1) into a colorscale with the colors transformed into rgb colors
-
plotly.express.colors.
convert_dict_colors_to_same_type
(colors_dict, colortype='rgb')¶ Converts a colors in a dictionary of colors to the specified color type
- Parameters
colors_dict ((dict)) – a dictionary whose values are single colors
-
plotly.express.colors.
convert_to_RGB_255
(colors)¶ Multiplies each element of a triplet by 255
Each coordinate of the color tuple is rounded to the nearest float and then is turned into an integer. If a number is of the form x.5, then if x is odd, the number rounds up to (x+1). Otherwise, it rounds down to just x. This is the way rounding works in Python 3 and in current statistical analysis to avoid rounding bias
- Parameters
rgb_components ((list)) – grabs the three R, G and B values to be returned as computed in the function
-
plotly.express.colors.
find_intermediate_color
(lowcolor, highcolor, intermed, colortype='tuple')¶ Returns the color at a given distance between two colors
This function takes two color tuples, where each element is between 0 and 1, along with a value 0 < intermed < 1 and returns a color that is intermed-percent from lowcolor to highcolor. If colortype is set to ‘rgb’, the function will automatically convert the rgb type to a tuple, find the intermediate color and return it as an rgb color.
-
plotly.express.colors.
get_colorscale
(name)¶ Returns the colorscale for a given name. See
named_colorscales
for the built-in colorscales.
-
plotly.express.colors.
hex_to_rgb
(value)¶ Calculates rgb values from a hex color code.
- Parameters
value ((string)) – Hex color string
- Rtype (tuple) (r_value, g_value, b_value)
tuple of rgb values
-
plotly.express.colors.
label_rgb
(colors)¶ Takes tuple (a, b, c) and returns an rgb color ‘rgb(a, b, c)’
-
plotly.express.colors.
make_colorscale
(colors, scale=None)¶ Makes a colorscale from a list of colors and a scale
Takes a list of colors and scales and constructs a colorscale based on the colors in sequential order. If ‘scale’ is left empty, a linear- interpolated colorscale will be generated. If ‘scale’ is a specificed list, it must be the same legnth as colors and must contain all floats For documentation regarding to the form of the output, see https://plot.ly/python/reference/#mesh3d-colorscale
- Parameters
colors ((list)) – a list of single colors
-
plotly.express.colors.
n_colors
(lowcolor, highcolor, n_colors, colortype='tuple')¶ Splits a low and high color into a list of n_colors colors in it
Accepts two color tuples and returns a list of n_colors colors which form the intermediate colors between lowcolor and highcolor from linearly interpolating through RGB space. If colortype is ‘rgb’ the function will return a list of colors in the same form.
-
plotly.express.colors.
named_colorscales
()¶ Returns lowercased names of built-in continuous colorscales.
-
plotly.express.colors.
sample_colorscale
(colorscale, samplepoints, low=0.0, high=1.0, colortype='rgb')¶ Samples a colorscale at specific points.
Interpolates between colors in a colorscale to find the specific colors corresponding to the specified sample values. The colorscale can be specified as a list of
[scale, color]
pairs, as a list of colors, or as a named plotly colorscale. The samplepoints can be specefied as an iterable of specific points in the range [0.0, 1.0], or as an integer number of points which will be spaced equally between the low value (default 0.0) and the high value (default 1.0). The output is a list of colors, formatted according to the specified colortype.
-
plotly.express.colors.
unconvert_from_RGB_255
(colors)¶ Return a tuple where each element gets divided by 255
Takes a (list of) color tuple(s) where each element is between 0 and 255. Returns the same tuples where each tuple element is normalized to a value between 0 and 1
-
plotly.express.colors.
unlabel_rgb
(colors)¶ Takes rgb color(s) ‘rgb(a, b, c)’ and returns tuple(s) (a, b, c)
This function takes either an ‘rgb(a, b, c)’ color or a list of such colors and returns the color tuples in tuple(s) (a, b, c)
-
plotly.express.colors.
validate_colors
(colors, colortype='tuple')¶ Validates color(s) and returns a list of color(s) of a specified type
-
plotly.express.colors.
validate_colors_dict
(colors, colortype='tuple')¶ Validates dictionary of color(s)
-
plotly.express.colors.
validate_colorscale
(colorscale)¶ Validate the structure, scale values and colors of colorscale.
-
plotly.express.colors.
validate_scale_values
(scale)¶ Validates scale values from a colorscale
- Parameters
scale ((list)) – a strictly increasing list of floats that begins with 0 and ends with 1. Its usage derives from a colorscale which is a list of two-lists (a list with two elements) of the form [value, color] which are used to determine how interpolation weighting works between the colors in the colorscale. Therefore scale is just the extraction of these values from the two-lists in order
Submodules¶
plotly.express.colors.carto module¶
Color sequences and scales from CARTO’s CartoColors
Learn more at https://github.com/CartoDB/CartoColor
CARTOColors are made available under a Creative Commons Attribution license: https://creativecommons.org/licenses/by/3.0/us/
plotly.express.colors.cmocean module¶
Color scales from the cmocean project
Learn more at https://matplotlib.org/cmocean/
cmocean is made available under an MIT license: https://github.com/matplotlib/cmocean/blob/master/LICENSE.txt
plotly.express.colors.colorbrewer module¶
Color scales and sequences from the colorbrewer 2 project
Learn more at http://colorbrewer2.org
colorbrewer is made available under an Apache license: http://colorbrewer2.org/export/LICENSE.txt
plotly.express.colors.cyclical module¶
Cyclical color scales are appropriate for continuous data that has a natural cyclical structure, such as temporal data (hour of day, day of week, day of year, seasons) or complex numbers or other phase data.
-
plotly.express.colors.cyclical.
swatches
(template=None)¶ - Parameters
template (str or dict or plotly.graph_objects.layout.Template instance) – The figure template name or definition.
- Returns
fig – A
Figure
object. This figure demonstrates the color scales and sequences in this module, as stacked bar charts.- Return type
graph_objects.Figure containing the displayed image
-
plotly.express.colors.cyclical.
swatches_cyclical
(template=None)¶ - Parameters
template (str or dict or plotly.graph_objects.layout.Template instance) – The figure template name or definition.
- Returns
fig – A
Figure
object. This figure demonstrates the color scales and sequences in this module, as polar bar charts.- Return type
graph_objects.Figure containing the displayed image
plotly.express.colors.diverging module¶
Diverging color scales are appropriate for continuous data that has a natural midpoint other otherwise informative special value, such as 0 altitude, or the boiling point
of a liquid. The color scales in this module are mostly meant to be passed in as the color_continuous_scale
argument to various functions, and to be used with the color_continuous_midpoint
argument.
-
plotly.express.colors.diverging.
swatches
(template=None)¶ - Parameters
template (str or dict or plotly.graph_objects.layout.Template instance) – The figure template name or definition.
- Returns
fig – A
Figure
object. This figure demonstrates the color scales and sequences in this module, as stacked bar charts.- Return type
graph_objects.Figure containing the displayed image
plotly.express.colors.qualitative module¶
Qualitative color sequences are appropriate for data that has no natural ordering, such as categories, colors, names, countries etc. The color sequences in this module are mostly meant to be passed in as the color_discrete_sequence
argument to various functions.
-
plotly.express.colors.qualitative.
swatches
(template=None)¶ - Parameters
template (str or dict or plotly.graph_objects.layout.Template instance) – The figure template name or definition.
- Returns
fig – A
Figure
object. This figure demonstrates the color scales and sequences in this module, as stacked bar charts.- Return type
graph_objects.Figure containing the displayed image
plotly.express.colors.sequential module¶
Sequential color scales are appropriate for most continuous data, but in some cases it can be helpful to use a plotly.colors.diverging
or plotly.colors.cyclical
scale instead. The color scales in this module are mostly meant to be passed in as the color_continuous_scale
argument to various functions.
-
plotly.express.colors.sequential.
swatches
(template=None)¶ - Parameters
template (str or dict or plotly.graph_objects.layout.Template instance) – The figure template name or definition.
- Returns
fig – A
Figure
object. This figure demonstrates the color scales and sequences in this module, as stacked bar charts.- Return type
graph_objects.Figure containing the displayed image