Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix `convert_dash` mapping dotted lines (`linestyle=':'`) to invalid `'circle'` in Plotly, correctly converting them to `'dot'` and preserving custom dash patterns as pixel lists, [[#5719](https://github.com/plotly/plotly.py/pull/5719)] with thanks to @robertoffmoura for the contribution!
- Fix Plotly Express mutating lists passed to the `x` or `y` arguments in wide mode [[#5727](https://github.com/plotly/plotly.py/pull/5727)], with thanks to @cpruijsen for the contribution!
- Fix `px.sunburst`, `px.treemap` and `px.icicle` listing sectors in a different order on every run when `path` is used with a Polars DataFrame; sectors now follow their order of first appearance for all dataframe backends [[#5766](https://github.com/plotly/plotly.py/pull/5766)], with thanks to @Irahan2 for the contribution!
- Fix `trendline_scope="overall"` drawing the overall trendline on the `marginal_x`/`marginal_y` subplots as well as the main plot; it is now drawn only on the main subplots [[#5780](https://github.com/plotly/plotly.py/pull/5780)], with thanks to @jayzhou2309 for the contribution!
- Fix `mpl_to_plotly` conversion of matplotlib contour lines and line collections: close contour rings ending with `Z` codes, support dash styles, convert date x-axes, separate disjoint subpaths with `None` separators, hide line collection traces from the legend by default, and group consecutive same-style lines into single traces [[#5770](https://github.com/plotly/plotly.py/pull/5770)], with thanks to @robertoffmoura for the contribution!
- Fix `plotly.io.write_images` ignoring `layout.width`/`layout.height` (and the template's) and exporting every figure at the default 700x500 size; it now uses the same width/height priority as `write_image` and `to_image` [[#5784](https://github.com/plotly/plotly.py/pull/5784)], with thanks to @breken-ai for the contribution!
- Fix color utilities mutating the list of colors passed to them [[#5836](https://github.com/plotly/plotly.py/pull/5836)], with thanks to @Enesuygurs for the contribution!
Expand Down
10 changes: 7 additions & 3 deletions plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2834,9 +2834,13 @@ def make_figure(args, constructor, trace_patch=None, layout_patch=None):
args, trendline_spec, args["data_frame"], {}, sizeref
)
trendline_trace.update(patch)
fig.add_trace(
trendline_trace, row="all", col="all", exclude_empty_subplots=True
)
main_rows = nrows - 1 if args.get("marginal_x") is not None else nrows
main_cols = ncols - 1 if args.get("marginal_y") is not None else ncols
for row in range(1, main_rows + 1):
for col in range(1, main_cols + 1):
fig.add_trace(
trendline_trace, row=row, col=col, exclude_empty_subplots=True
)
fig.update_traces(selector=-1, showlegend=True)
if fit_results is not None:
trendline_rows.append(dict(px_fit_results=fit_results))
Expand Down
31 changes: 31 additions & 0 deletions tests/test_optional/test_px/test_trendline.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,34 @@ def test_overall_trendline(backend):
params3 = results3["px_fit_results"].iloc[0].params

assert np.all(np.array_equal(params1, params3))


@pytest.mark.parametrize(
"kwargs",
[
dict(marginal_x="box", marginal_y="box"),
dict(marginal_x="histogram", facet_col="smoker"),
dict(marginal_y="violin", facet_row="smoker"),
],
)
def test_overall_trendline_skips_marginals(backend, kwargs):
df = px.data.tips(return_type=backend)
fig = px.scatter(
df,
x="total_bill",
y="tip",
color="sex",
trendline="ols",
trendline_scope="overall",
**kwargs,
)
trendline_axes = [
(t.xaxis, t.yaxis) for t in fig.data if t.name == "Overall Trendline"
]
scatter_axes = {
(t.xaxis, t.yaxis)
for t in fig.data
if t.type == "scatter" and t.name != "Overall Trendline"
}
assert len(trendline_axes) == len(scatter_axes)
assert set(trendline_axes) == scatter_axes