Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add facet_row support to px.imshow #5445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
FBumann wants to merge 3 commits into plotly:main
base: main
Choose a base branch
Loading
from FBumann:main
Open

Conversation

@FBumann
Copy link

@FBumann FBumann commented Dec 6, 2025
edited
Loading

Summary

This PR adds facet_row support to plotly.express.imshow, enabling visualization of 4D and 5D data by faceting along both row and column dimensions.

Closes #4108

Motivation

Currently, px.imshow only supports facet_col for creating faceted plots, limiting users to visualizing 3D data (with one facet dimension). Many scientific and
engineering use cases require visualizing 4D tensor data (e.g., full factorial experimental designs in ML and biological sciences). This PR enables users to use both
facet_row and facet_col simultaneously, along with animation_frame, to visualize up to 5D datasets.

Changes

plotly/express/_imshow.py

  • Added facet_row parameter to the function signature
  • Updated docstring to document the new parameter
  • Updated slice dimension calculations to handle both facet_row and facet_col
  • Updated xarray handling to extract facet_row dimension labels
  • Updated array reshaping to handle the additional dimension
  • Updated figure building to generate row labels and place traces correctly
  • Note: facet_col_wrap is ignored when facet_row is set (consistent with other px functions)

tests/test_optional/test_px/test_imshow.py

  • Added test_facet_row: Tests facet_row with numpy arrays
  • Added test_facet_row_and_col: Tests using both facet_row and facet_col together
  • Added test_animation_facet_row_and_col: Tests animation + facet_row + facet_col
  • Added test_imshow_xarray_facet_row: Tests facet_row with xarray
  • Added test_imshow_xarray_facet_row_and_col: Tests both facets with xarray

Example Usage

import plotly.express as px
# Prepare data for multi dimensional usage
df = px.data.tips()
cols = ['smoker', 'sex', 'time', 'day', 'size']
pivot = df.groupby(cols)['total_bill'].mean().reset_index()
da = pivot.set_index(cols).to_xarray()['total_bill']
# 4D data: visualize with facet_row and facet_col
fig1 = px.imshow(da.sum('day'), facet_row="smoker", facet_col="sex")
fig1.show()
# Also works with numpy
fig2 = px.imshow(da.sum('day').values, facet_row=0, facet_col=1)
fig2.show()
# 5D data: animation + facet_row + facet_col
fig3 = px.imshow(da, facet_row="smoker", facet_col="sex", animation_frame='day')
fig3.show()

@FBumann FBumann changed the title (削除) eat: Add facet_row support to px.imshow (削除ここまで) (追記) feat: Add facet_row support to px.imshow (追記ここまで) Dec 6, 2025
@FBumann FBumann marked this pull request as ready for review December 6, 2025 15:21
Copy link
Author

FBumann commented Dec 6, 2025

Build fails are unrelated to changes afaik. #5442

Copy link
Contributor

emilykl commented Dec 8, 2025

Build fails are unrelated to changes afaik. #5442

@FBumann You're right, #5442 has been merged so the docs build should be fixed on main; you can update this branch and run CI again.

Copy link
Author

FBumann commented Dec 8, 2025

@emilykl Ready for review

Copy link
Author

FBumann commented Jan 8, 2026

Any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

add facet_row support in px.imshow

2 participants

AltStyle によって変換されたページ (->オリジナル) /