Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added
- Add the `custom_data` argument to `px.histogram`, so extra columns can be attached to histogram traces for use in Dash callbacks and selection events, as in the other Plotly Express functions [[#3859](https://github.com/plotly/plotly.py/issues/3859)]

### Fixed
- Fix `mpl_to_plotly` tick marker mirroring, axis positioning, and trace visibility for twinned and overlaid subplots (such as `twinx` and `twiny`) [[#5310](https://github.com/plotly/plotly.py/pull/5310)], with thanks to @robertoffmoura for the contribution!
- Fix `mpl_to_plotly` losing matplotlib axis line colors by exporting the color of each axis's displayed spine to the plotly x and y axis `linecolor` [[#5311](https://github.com/plotly/plotly.py/pull/5311)], with thanks to @robertoffmoura for the contribution!
Expand Down
1 change: 1 addition & 0 deletions plotly/express/_chart_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def histogram(
facet_col_spacing=None,
hover_name=None,
hover_data=None,
custom_data=None,
animation_frame=None,
animation_group=None,
category_orders=None,
Expand Down
22 changes: 22 additions & 0 deletions tests/test_optional/test_px/test_px.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ def test_custom_data_scatter(backend):
)


def test_custom_data_histogram(backend):
tips = nw.from_native(px.data.tips(return_type=backend))
# No custom data
fig = px.histogram(tips.to_native(), x="total_bill")
assert fig.data[0].customdata is None
# Custom data is carried per row of the input, not per bin
fig = px.histogram(tips.to_native(), x="total_bill", custom_data=["tip", "day"])
assert fig.data[0].customdata.shape == (len(tips), 2)
assert np.all(fig.data[0].customdata[:, 0] == tips.get_column("tip").to_numpy())
assert np.all(fig.data[0].customdata[:, 1] == tips.get_column("day").to_numpy())
# Bins are aggregates, so custom data does not show up in the hover label
assert fig.data[0].hovertemplate == "total_bill=%{x}<br>count=%{y}<extra></extra>"
# Each colored trace carries the custom data of its own rows
fig = px.histogram(
tips.to_native(), x="total_bill", color="sex", custom_data=["tip"]
)
for trace in fig.data:
group = tips.filter(nw.col("sex") == trace.name)
assert trace.customdata.shape == (len(group), 1)
assert np.all(trace.customdata[:, 0] == group.get_column("tip").to_numpy())


def test_labels(backend):
tips = nw.from_native(px.data.tips(return_type=backend))
fig = px.scatter(
Expand Down