Skip to content

Commit 351a3c2

Browse files
set line_group in wide mode
1 parent e281bc9 commit 351a3c2

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
- Fixed special cases with `px.sunburst` and `px.treemap` with `path` input ([#2524](https://github.com/plotly/plotly.py/pull/2524))
1010
- Fixed bug in `hover_data` argument of `px` functions, when the column name is changed with labels and `hover_data` is a dictionary setting up a specific format for the hover data ([#2544](https://github.com/plotly/plotly.py/pull/2544)).
1111
- Made the Plotly Express `trendline` argument more robust and made it work with datetime `x` values ([#2554](https://github.com/plotly/plotly.py/pull/2554))
12+
- `px.line` now sets `line_group=<variable>` in wide mode by default ([#2599](https://github.com/plotly/plotly.py/pull/2599))
1213

1314
## [4.8.1] - 2020-05-28
1415

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

+2
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,8 @@ def build_dataframe(args, constructor):
14161416
args["y" if orient_v else "x"] = value_name
14171417
if constructor != go.Histogram2d:
14181418
args["color"] = args["color"] or var_name
1419+
if "line_group" in args:
1420+
args["line_group"] = args["line_group"] or var_name
14191421
if constructor == go.Bar:
14201422
if _is_continuous(df_output, value_name):
14211423
args["x" if orient_v else "y"] = wide_cross_name

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

+17
Original file line numberDiff line numberDiff line change
@@ -742,3 +742,20 @@ def test_mixed_input_error(df):
742742
"Plotly Express cannot process wide-form data with columns of different type"
743743
in str(err_msg.value)
744744
)
745+
746+
747+
def test_line_group():
748+
df = pd.DataFrame(
749+
data={
750+
"who": ["a", "a", "b", "b"],
751+
"x": [0, 1, 0, 1],
752+
"score": [1.0, 2, 3, 4],
753+
"miss": [3.2, 2.5, 1.3, 1.5],
754+
}
755+
)
756+
fig = px.line(df, x="x", y=["miss", "score"])
757+
assert len(fig.data) == 2
758+
fig = px.line(df, x="x", y=["miss", "score"], color="who")
759+
assert len(fig.data) == 4
760+
fig = px.scatter(df, x="x", y=["miss", "score"], color="who")
761+
assert len(fig.data) == 2

0 commit comments

Comments
 (0)