Skip to content

Commit f318313

Browse files
committed
Add px.scatter_smith and support smith subplots in make_subplots
Closes #4731
1 parent 38374ac commit f318313

12 files changed

Lines changed: 139 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## Unreleased
66

7+
### Added
8+
- Add `px.scatter_smith` for plotting complex values (`real` and `imag`) on Smith charts, and support the `"smith"` subplot type in `make_subplots` [[#5824](https://github.com/plotly/plotly.py/pull/5824)], with thanks to @ybai08 for the contribution!
9+
710
### Fixed
811
- 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!
912
- 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!

‎doc/apidoc/plotly.express.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ plotly's high-level API for rapid figure generation. ::
1818
scatter_3d
1919
scatter_polar
2020
scatter_ternary
21+
scatter_smith
2122
scatter_map
2223
scatter_geo
2324
line

‎doc/python/smith-charts.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ jupyter:
3838
A [Smith Chart](https://en.wikipedia.org/wiki/Smith_chart) is a specialized chart for visualizing [complex numbers](https://en.wikipedia.org/wiki/Complex_number): numbers with both a real and imaginary part.
3939

4040

41+
### Smith Charts with Plotly Express
42+
43+
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/). With `px.scatter_smith`, each row of the DataFrame is represented as a marker on the Smith chart, with `real` and `imag` giving the real and imaginary parts of its normalized impedance.
44+
45+
```python
46+
import plotly.express as px
47+
import pandas as pd
48+
49+
df = pd.DataFrame({
50+
"real": [0.2, 0.5, 1.0, 2.0, 0.2, 0.5, 1.0, 2.0],
51+
"imag": [0.5, 1.0, 0.5, -1.0, -0.5, -1.0, 2.0, 0.0],
52+
"antenna": ["A", "A", "A", "A", "B", "B", "B", "B"],
53+
})
54+
55+
fig = px.scatter_smith(df, real="real", imag="imag", color="antenna")
56+
fig.show()
57+
```
58+
4159
### Smith Charts with Plotly Graph Objects
4260

4361
```python

‎plotly/_subplots.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# little differently.
99
import collections
1010

11-
_single_subplot_types = {"scene", "geo", "polar", "ternary", "map"}
11+
_single_subplot_types = {"scene", "geo", "polar", "ternary", "map", "smith"}
1212
_subplot_types = set.union(_single_subplot_types, {"xy", "domain"})
1313

1414
# For most subplot types, a trace is associated with a particular subplot
@@ -20,7 +20,7 @@
2020
# the trace property is just named `subplot`. For example setting
2121
# the `scatterpolar.subplot` property to `polar3` associates the scatterpolar
2222
# trace with the third polar subplot in the figure
23-
_subplot_prop_named_subplot = {"polar", "ternary", "map"}
23+
_subplot_prop_named_subplot = {"polar", "ternary", "map", "smith"}
2424

2525

2626
# Named tuple to hold an xaxis/yaxis pair that represent a single subplot
@@ -152,6 +152,7 @@ def make_subplots(
152152
- 'polar': Polar subplot for scatterpolar, barpolar, etc.
153153
- 'ternary': Ternary subplot for scatterternary
154154
- 'map': Map subplot for scattermap, choroplethmap and densitymap
155+
- 'smith': Smith chart subplot for scattersmith
155156
- 'domain': Subplot type for traces that are individually
156157
positioned. pie, parcoords, parcats, etc.
157158
- trace type: A trace type which will be used to determine

‎plotly/basedatatypes.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,7 @@ def get_subplot(self, row, col, secondary_y=False):
24282428
* plotly.graph_objs.layout.Polar: if subplot type is 'polar'
24292429
* plotly.graph_objs.layout.Ternary: if subplot type is 'ternary'
24302430
* plotly.graph_objs.layout.Map: if subplot type is 'map'
2431+
* plotly.graph_objs.layout.Smith: if subplot type is 'smith'
24312432
* SubplotDomain namedtuple with `x` and `y` fields:
24322433
if subplot type is 'domain'.
24332434
- x: length 2 list of the subplot start and stop width

‎plotly/express/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
scatter_3d,
3131
scatter_polar,
3232
scatter_ternary,
33+
scatter_smith,
3334
scatter_map,
3435
scatter_geo,
3536
line,
@@ -79,6 +80,7 @@
7980
"scatter_3d",
8081
"scatter_polar",
8182
"scatter_ternary",
83+
"scatter_smith",
8284
"scatter_map",
8385
"scatter_geo",
8486
"scatter_matrix",

‎plotly/express/_chart_types.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,47 @@ def line_ternary(
937937
line_ternary.__doc__ = make_docstring(line_ternary)
938938

939939

940+
def scatter_smith(
941+
data_frame=None,
942+
real=None,
943+
imag=None,
944+
color=None,
945+
symbol=None,
946+
size=None,
947+
text=None,
948+
hover_name=None,
949+
hover_data=None,
950+
custom_data=None,
951+
animation_frame=None,
952+
animation_group=None,
953+
category_orders=None,
954+
labels=None,
955+
color_discrete_sequence=None,
956+
color_discrete_map=None,
957+
color_continuous_scale=None,
958+
range_color=None,
959+
color_continuous_midpoint=None,
960+
symbol_sequence=None,
961+
symbol_map=None,
962+
opacity=None,
963+
size_max=None,
964+
title=None,
965+
subtitle=None,
966+
template=None,
967+
width=None,
968+
height=None,
969+
) -> go.Figure:
970+
"""
971+
In a Smith chart scatter plot, each row of `data_frame` is represented by
972+
a symbol mark in Smith chart coordinates, positioned by its normalized
973+
impedance (`real` + `imag` * j).
974+
"""
975+
return make_figure(args=locals(), constructor=go.Scattersmith)
976+
977+
978+
scatter_smith.__doc__ = make_docstring(scatter_smith)
979+
980+
940981
def scatter_polar(
941982
data_frame=None,
942983
r=None,

‎plotly/express/_core.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
# Declare all supported attributes, across all plot types
3232
direct_attrables = (
33-
["base", "x", "y", "z", "a", "b", "c", "r", "theta", "size", "x_start", "x_end"]
34-
+ ["hover_name", "text", "names", "values", "parents", "wide_cross"]
35-
+ ["ids", "error_x", "error_x_minus", "error_y", "error_y_minus", "error_z"]
36-
+ ["error_z_minus", "lat", "lon", "locations", "animation_group"]
33+
["base", "x", "y", "z", "a", "b", "c", "r", "theta", "real", "imag", "size"]
34+
+ ["x_start", "x_end", "hover_name", "text", "names", "values", "parents"]
35+
+ ["wide_cross", "ids", "error_x", "error_x_minus", "error_y", "error_y_minus"]
36+
+ ["error_z", "error_z_minus", "lat", "lon", "locations", "animation_group"]
3737
)
3838
array_attrables = ["dimensions", "custom_data", "hover_data", "path", "wide_variable"]
3939
group_attrables = ["animation_frame", "facet_row", "facet_col", "line_group"]
@@ -2893,7 +2893,7 @@ def init_figure(args, subplot_type, frame_list, nrows, ncols, col_labels, row_la
28932893
horizontal_spacing = args.get("facet_col_spacing") or 0.02
28942894
else:
28952895
# Other subplot types:
2896-
# 'scene', 'geo', 'polar', 'ternary', 'map', 'domain', None
2896+
# 'scene', 'geo', 'polar', 'ternary', 'map', 'smith', 'domain', None
28972897
#
28982898
# We can customize subplot spacing per type once we enable faceting
28992899
# for all plot types

‎plotly/express/_doc.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@
7373
colref_desc,
7474
"Values from this column or array_like are used to position marks along the angular axis in polar coordinates.",
7575
],
76+
real=[
77+
colref_type,
78+
colref_desc,
79+
"Values from this column or array_like are used as the real part of the normalized impedance of marks in Smith chart coordinates.",
80+
],
81+
imag=[
82+
colref_type,
83+
colref_desc,
84+
"Values from this column or array_like are used as the imaginary part of the normalized impedance of marks in Smith chart coordinates.",
85+
],
7686
values=[
7787
colref_type,
7888
colref_desc,

‎plotly/subplots.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def make_subplots(
115115
- 'polar': Polar subplot for scatterpolar, barpolar, etc.
116116
- 'ternary': Ternary subplot for scatterternary
117117
- 'map': Map subplot for scattermap
118+
- 'smith': Smith chart subplot for scattersmith
118119
- 'domain': Subplot type for traces that are individually
119120
positioned. pie, parcoords, parcats, etc.
120121
- trace type: A trace type which will be used to determine

0 commit comments

Comments
 (0)