plotly.express.colors package — 5.22.0 documentation (2024)

For a list of colors available in plotly.express.colors, please see

  • the tutorial on discrete color sequences

  • the list of built-in continuous color scales

  • the tutorial on continuous colors

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 objectis an iterable or not and applies the given color-parsing function tothe color or iterable of colors. If given an iterable, it will only beable 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 scalevalues, and outputs a 2-pair of the list of color(s) converted all to anrgb or tuple color type, aswell as the scale as the second element. Ifcolors is a Plotly Scale name, then ‘scale’ will be forced to the scalefrom the respective colorscale and the colors in that colorscale will alsobe coverted to the selected colortype. If colors is None, then there is anoption to return portion of the DEFAULT_PLOTLY_COLORS

Parameters
  • colors ((str|tuple|list)) – either a plotly scale name, an rgb or hexcolor, 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 thefirst item and a color as the second. This function specifically isconverting a colorscale with tuple colors (each coordinate between 0and 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 andthen is turned into an integer. If a number is of the form x.5, thenif x is odd, the number rounds up to (x+1). Otherwise, it rounds downto just x. This is the way rounding works in Python 3 and in currentstatistical analysis to avoid rounding bias

Parameters

rgb_components ((list)) – grabs the three R, G and B values to bereturned 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 0and 1, along with a value 0 < intermed < 1 and returns a color that isintermed-percent from lowcolor to highcolor. If colortype is set to ‘rgb’,the function will automatically convert the rgb type to a tuple, find theintermediate 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 thebuilt-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 basedon the colors in sequential order. If ‘scale’ is left empty, a linear-interpolated colorscale will be generated. If ‘scale’ is a specificedlist, it must be the same legnth as colors and must contain all floatsFor documentation regarding to the form of the output, seehttps://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 colorswhich form the intermediate colors between lowcolor and highcolorfrom 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 colorscorresponding to the specified sample values. The colorscale can be specifiedas a list of [scale, color] pairs, as a list of colors, or as a namedplotly colorscale. The samplepoints can be specefied as an iterable of specificpoints in the range [0.0, 1.0], or as an integer number of points which willbe 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 thespecified 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 and255. Returns the same tuples where each tuple element is normalized toa 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 ofsuch 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 beginswith 0 and ends with 1. Its usage derives from a colorscale which isa list of two-lists (a list with two elements) of the form[value, color] which are used to determine how interpolation weightingworks between the colors in the colorscale. Therefore scale is justthe 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) orcomplex 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 andsequences 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 andsequences 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 pointof 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 andsequences 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 andsequences 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 andsequences in this module, as stacked bar charts.

Return type

graph_objects.Figure containing the displayed image

plotly.express.colors package —  5.22.0 documentation (2024)

References

Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 6042

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.