diff --git a/CHANGELOG.md b/CHANGELOG.md index d6b656d456..625c7cb83a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - 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)) - Plotly Express wide mode now accepts mixed integer and float columns ([#2598](https://github.com/plotly/plotly.py/pull/2598)) - Plotly Express `range_(x|y)` should not impact the unlinked range of marginal subplots ([#2600](https://github.com/plotly/plotly.py/pull/2600)) +- `px.line` now sets `line_group=` in wide mode by default ([#2599](https://github.com/plotly/plotly.py/pull/2599)) ## [4.8.1] - 2020-05-28 diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 53688b1050..18ea28d2ab 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -1422,6 +1422,8 @@ def build_dataframe(args, constructor): args["y" if orient_v else "x"] = value_name if constructor != go.Histogram2d: args["color"] = args["color"] or var_name + if "line_group" in args: + args["line_group"] = args["line_group"] or var_name if constructor == go.Bar: if _is_continuous(df_output, value_name): args["x" if orient_v else "y"] = wide_cross_name diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py index 87aff6fac2..ebd650371f 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py @@ -748,3 +748,20 @@ def test_mixed_number_input(): df = pd.DataFrame(dict(a=[1, 2], b=[1.1, 2.1])) fig = px.line(df) assert len(fig.data) == 2 + + +def test_line_group(): + df = pd.DataFrame( + data={ + "who": ["a", "a", "b", "b"], + "x": [0, 1, 0, 1], + "score": [1.0, 2, 3, 4], + "miss": [3.2, 2.5, 1.3, 1.5], + } + ) + fig = px.line(df, x="x", y=["miss", "score"]) + assert len(fig.data) == 2 + fig = px.line(df, x="x", y=["miss", "score"], color="who") + assert len(fig.data) == 4 + fig = px.scatter(df, x="x", y=["miss", "score"], color="who") + assert len(fig.data) == 2