Skip to content

Commit 7ad9b69

Browse files
committed
corrected color bug in pie/sunburst etc
1 parent 4a7465c commit 7ad9b69

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/python/plotly/plotly/express/_core.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
331331
mapping_labels[attr_label] = "%{color}"
332332
else:
333333
trace_patch["marker"]["colors"] = []
334-
mapping = {}
334+
if args["color_discrete_map"] is not None:
335+
mapping = args["color_discrete_map"].copy()
336+
else:
337+
mapping = {}
335338
for cat in trace_data[attr_value]:
336339
if mapping.get(cat) is None:
337340
mapping[cat] = args["color_discrete_sequence"][

packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py

+5
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ def test_sunburst_treemap_with_path_color():
218218
fig = px.sunburst(df, path=path, color="vendors")
219219
assert len(np.unique(fig.data[0].marker.colors)) == 9
220220

221+
# Discrete color and color_discrete_map
222+
cmap = {"Tech": "yellow", "Finance": "magenta", "(?)": "black"}
223+
fig = px.sunburst(df, path=path, color="sectors", color_discrete_map=cmap)
224+
assert np.all(np.in1d(fig.data[0].marker.colors, list(cmap.values())))
225+
221226
# Numerical column in path
222227
df["regions"] = df["regions"].map({"North": 1, "South": 2})
223228
path = ["total", "regions", "sectors", "vendors"]

0 commit comments

Comments
 (0)