Skip to content

Commit ffc29e6

Browse files
px.NO_COLOR
1 parent fb84bc5 commit ffc29e6

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [4.9.0] - unreleased
6+
7+
### Added
8+
9+
- `px.NO_COLOR` constant to override wide-form color assignment
10+
11+
512
## [4.8.2] - 2020-06-26
613

714
### Updated

Diff for: packages/python/plotly/plotly/express/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
set_mapbox_access_token,
5454
defaults,
5555
get_trendline_results,
56+
NO_COLOR,
5657
)
5758

5859
from ._special_inputs import IdentityMap, Constant, Range # noqa: F401
@@ -100,4 +101,5 @@
100101
"IdentityMap",
101102
"Constant",
102103
"Range",
104+
"NO_COLOR",
103105
]

Diff for: packages/python/plotly/plotly/express/_core.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
_subplot_type_for_trace_type,
1616
)
1717

18+
NO_COLOR = "px_no_color_constant"
1819

1920
# Declare all supported attributes, across all plot types
2021
direct_attrables = (
@@ -1349,6 +1350,10 @@ def build_dataframe(args, constructor):
13491350
label=_escape_col_name(df_input, "index", [var_name, value_name])
13501351
)
13511352

1353+
no_color = False
1354+
if args.get("color", None) == NO_COLOR:
1355+
no_color = True
1356+
args["color"] = None
13521357
# now that things have been prepped, we do the systematic rewriting of `args`
13531358

13541359
df_output, wide_id_vars = process_args_into_dataframe(
@@ -1440,7 +1445,8 @@ def build_dataframe(args, constructor):
14401445
args["x" if orient_v else "y"] = value_name
14411446
args["y" if orient_v else "x"] = wide_cross_name
14421447
args["color"] = args["color"] or var_name
1443-
1448+
if no_color:
1449+
args["color"] = None
14441450
args["data_frame"] = df_output
14451451
return args
14461452

Diff for: packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py

+11
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,17 @@ def append_special_case(df_in, args_in, args_expect, df_expect):
708708
),
709709
)
710710

711+
# NO_COLOR
712+
df = pd.DataFrame(dict(a=[1, 2], b=[3, 4]))
713+
append_special_case(
714+
df_in=df,
715+
args_in=dict(x=None, y=None, color=px.NO_COLOR),
716+
args_expect=dict(x="index", y="value", color=None, orientation="v",),
717+
df_expect=pd.DataFrame(
718+
dict(variable=["a", "a", "b", "b"], index=[0, 1, 0, 1], value=[1, 2, 3, 4])
719+
),
720+
)
721+
711722

712723
@pytest.mark.parametrize("df_in, args_in, args_expect, df_expect", special_cases)
713724
def test_wide_mode_internal_special_cases(df_in, args_in, args_expect, df_expect):

0 commit comments

Comments
 (0)