Skip to content

Add px.scatter_smith and support smith subplots in make_subplots - #5824

Open
ybai08 wants to merge 1 commit into
plotly:mainfrom
ybai08:px-scatter-smith
Open

ybai08 wants to merge 1 commit into
plotly:mainfrom
ybai08:px-scatter-smith

Conversation

@ybai08

@ybai08 ybai08 commented Oct 17, 2026

Copy link
Copy Markdown

Link to issue

Closes #4731

Description of change

Adds px.scatter_smith(data_frame, real=..., imag=..., ...), which builds go.Scattersmith traces the same way px.scatter_ternary builds go.Scatterternary traces, with the same arguments for color, symbol, size, text, hover, custom data and animation. To make that work, make_subplots now accepts "smith" (and "scattersmith") as a subplot type. Before this change it raised ValueError: Unsupported subplot type: 'smith', and every px figure goes through make_subplots.

Details:

  • plotly/_subplots.py: added "smith" to _single_subplot_types and _subplot_prop_named_subplot. Smith traces use the subplot property, like polar, ternary and map. With that, make_subplots sets layout.smith/smith2/... domains, add_trace(..., row=, col=) assigns subplot="smith2", and get_subplot / update_traces(row=, col=) resolve smith cells.
  • plotly/express: added real/imag to the direct attributes, right after r/theta, so hover lines come out in the same order as the other coordinate systems (real=%{real}<br>imag=%{imag}). Also added their docstrings, the scatter_smith function and the export. The smith layout axes have no title property, so no axis configurator is needed.
  • Docs: a Plotly Express section in doc/python/smith-charts.md, an apidoc entry, and the make_subplots / get_subplot docstrings.
  • CHANGELOG.md entry under Unreleased / Added.

I kept the change to scatter_smith, as the issue asks. A line_smith counterpart, like line_ternary/line_polar, would be a few more lines if you want it here or in a follow-up.

Demo

import plotly.express as px
import pandas as pd

df = pd.DataFrame({
    "real": [0.2, 0.5, 1.0, 2.0, 0.2, 0.5, 1.0, 2.0],
    "imag": [0.5, 1.0, 0.5, -1.0, -0.5, -1.0, 2.0, 0.0],
    "antenna": ["A", "A", "A", "A", "B", "B", "B", "B"],
})
fig = px.scatter_smith(df, real="real", imag="imag", color="antenna")
# two scattersmith traces ("A", "B") on layout.smith
# hovertemplate: "antenna=A<br>real=%{real}<br>imag=%{imag}<extra></extra>"

No screenshot attached. The figure was checked through its JSON (trace types, data, subplot, hovertemplate) and not in a browser. %{real}/%{imag} in the hovertemplate rely on plotly.js copying array attributes into the hover event data and using the trace's realLabel/imagLabel, the same way %{r}/%{theta} work for scatterpolar.

Testing strategy

  • tests/test_core/test_subplots/test_get_subplot.py::test_get_subplot_smith: a 1x2 grid using "smith" and "scattersmith" gets the right domains, subplot assignment, get_subplot results and update_traces(row=, col=) targeting.
  • tests/test_optional/test_px/test_px_functions.py::test_scatter_smith_px compares against an equivalent go.Scattersmith figure. test_scatter_smith is parametrized over all dataframe constructors (pandas, pandas nullable/pyarrow, polars, pyarrow) and checks color grouping, data split, markers+text mode and the hovertemplate.

Without the source change, all 7 new tests fail: one with ValueError: Unsupported subplot type: 'smith' and six with AttributeError: module 'plotly.express' has no attribute 'scatter_smith'. With it they pass. Run locally on Python 3.12, macOS:

  • pytest tests/test_core: 456 passed, 1 skipped
  • pytest tests/test_optional/test_px: 1232 passed, 10 skipped, 4 xfailed
  • pytest tests/test_optional/test_subplots tests/test_optional/test_figure_factory: 25 passed
  • pytest tests/test_plotly_utils: 1423 passed
  • ruff format --check .: clean

Not run: tests/test_io (kaleido/Chrome), percy and the docs build.

Guidelines

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add scatter_smith to px

1 participant