Standardize color encoding
Apply one continuous palette across traces that use a shared color axis.
Plotly · Module
fig.update_coloraxes updates shared continuous-color settings on a Plotly figure, including the colorscale, color domain, and colorbar. It accepts color-axis properties as keyword arguments.
Call this method on a figure to change properties of its shared color axis, including the palette, numeric color domain, automatic range behavior, and colorbar settings. Keyword arguments map to color-axis properties, while nested colorbar options can be supplied either as a dictionary or through flattened names such as colorbar_title_text.
fig.update_coloraxes(arg=None, **kwargs)| Name | Type | Description |
|---|---|---|
autocolorscale | boolean | Whether to use a default colorscale instead of the palette specified by colorscale. |
cauto | boolean | Whether to compute the color domain from the input color data; defaults to false when cmin and cmax are set by the user. |
cmax | number | Upper bound of the color domain; cmin must also be set when this is provided. |
colorscale | colorscale | Colorscale mapping normalized values to supported color strings. |
colorbar | dict | Nested colorbar properties, including title, ticks, position, and styling. |
The page documents the update method and color-axis properties but does not specify a separate return value.
import plotly.express as px
fig = px.scatter(
px.data.iris(),
x="sepal_width",
y="sepal_length",
color="petal_length",
)
fig.update_coloraxes(colorscale="Viridis", cmin=1, cmax=7)
fig.show()Creates a scatter plot with a continuous color dimension, then sets the shared color axis palette and numeric domain.
Apply one continuous palette across traces that use a shared color axis.
Make colors represent a stable numeric interval across figures or subplots.
Control the colorbar's ticks, title, position, and appearance.
It updates properties of the figure's coloraxis, which controls continuous color settings shared by applicable traces. Common uses include changing the colorscale, fixing cmin and cmax, and configuring the colorbar.
Follow-up: How would you prevent the range from being inferred from the data? Set cauto to false and provide the intended cmin and cmax values.
The colorscale determines how normalized values map to colors. A custom scale is an array of position-color pairs, with positions normalized and colors expressed using supported CSS-like formats.
Follow-up: What must be true of a custom colorscale's positions? They should represent normalized values spanning the scale's domain.
cmin and cmax define the lower and upper bounds of the color domain. If cmax is supplied, the documentation says cmin must also be supplied, and both should use the units of the trace color arrays.
Follow-up: What happens when cauto remains enabled? The color domain is computed from the input color data rather than only from manually specified bounds.
layout.coloraxiscolorbarcolorscalecautocmincmaxfig.update_traces