Skip to content

Commit e53b165

Browse files
fix: DH-19036: Fix failing subplot creation (#1176)
Originally failing was the following: ``` import deephaven.plot.express as dx tips = dx.data.tips() # import a ticking version of the Tips dataset # create 4 plots from within make_subplots tipping_plots = dx.make_subplots( dx.scatter(tips, x="TotalBill", y="Tip", by="Sex", title="Tip amount by total bill"), dx.scatter(tips, x="TotalBill", y="Tip", by="Sex", title="Tip amount by total bill"), rows=2, cols=1, shared_xaxes=True, shared_yaxes=False ) ``` Added docs for shared axes as well --------- Co-authored-by: margaretkennedy <82049573+margaretkennedy@users.noreply.github.com>
1 parent c3c15e0 commit e53b165

4 files changed

Lines changed: 654 additions & 3 deletions

File tree

plugins/plotly-express/docs/sub-plots.md

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,110 @@ tipping_plots = dx.make_subplots(
3636

3737
![Sub Plot Basic Example](./_assets/sub_plot.png)
3838

39-
## API Reference
39+
### Share Axes
40+
41+
Share axes between plots with the `shared_xaxes` and `shared_yaxes` parameters.
42+
43+
#### Share All Axes
44+
45+
When `shared_xaxes` or `shared_yaxes` is set to `"all"`, all axes of the same type are shared.
46+
When one axis is adjusted, all axes are adjusted to match.
47+
48+
```python order=tipping_plots,lunch_tips,dinner_tips
49+
import deephaven.plot.express as dx
50+
tips = dx.data.tips() # import a ticking version of the Tips dataset
51+
52+
# filter the tips dataset for separate lunch and dinner charts
53+
lunch_tips = tips.where("Time = `Lunch`")
54+
dinner_tips = tips.where("Time = `Dinner`")
55+
56+
# create chart that shares all axes
57+
tipping_plots = dx.make_subplots(
58+
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
59+
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
60+
rows=2, shared_yaxes="all", shared_xaxes="all"
61+
)
62+
```
63+
64+
#### Share Y Axes
65+
66+
When `shared_yaxis` is set to `True`, all y axes are shared along the same row.
67+
When one y-axis is adjusted, all axes along the same row are adjusted to match.
68+
69+
```python order=tipping_plots,lunch_tips,dinner_tips
70+
import deephaven.plot.express as dx
71+
tips = dx.data.tips() # import a ticking version of the Tips dataset
72+
73+
# filter the tips dataset for separate lunch and dinner charts
74+
lunch_tips = tips.where("Time = `Lunch`")
75+
dinner_tips = tips.where("Time = `Dinner`")
76+
77+
# create chart that shares y axes along the row
78+
tipping_plots = dx.make_subplots(
79+
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
80+
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
81+
cols=2, shared_yaxes=True
82+
)
83+
```
84+
85+
To share the y axes along the same column, set `shared_yaxes` to `"columns"`.
86+
87+
```python order=tipping_plots,lunch_tips,dinner_tips
88+
import deephaven.plot.express as dx
89+
tips = dx.data.tips() # import a ticking version of the Tips dataset
4090

91+
# filter the tips dataset for separate lunch and dinner charts
92+
lunch_tips = tips.where("Time = `Lunch`")
93+
dinner_tips = tips.where("Time = `Dinner`")
94+
95+
# create chart that shares y axes along the column
96+
tipping_plots = dx.make_subplots(
97+
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
98+
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
99+
rows=2, shared_yaxes="columns"
100+
)
101+
```
102+
103+
#### Share X Axes
104+
105+
When `shared_xaxis` is set to `True`, all x axes are shared along the same column.
106+
When one x-axis is adjusted, all axes along the same column are adjusted to match.
107+
108+
```python order=tipping_plots,lunch_tips,dinner_tips
109+
import deephaven.plot.express as dx
110+
tips = dx.data.tips() # import a ticking version of the Tips dataset
111+
112+
# filter the tips dataset for separate lunch and dinner charts
113+
lunch_tips = tips.where("Time = `Lunch`")
114+
dinner_tips = tips.where("Time = `Dinner`")
115+
116+
# create chart that shares x axes along the column
117+
tipping_plots = dx.make_subplots(
118+
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
119+
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
120+
rows=2, shared_xaxes=True
121+
)
122+
```
123+
124+
To share the x axes along the same column, set `shared_yaxes` to `"columns"`.
125+
126+
```python order=tipping_plots,lunch_tips,dinner_tips
127+
import deephaven.plot.express as dx
128+
tips = dx.data.tips() # import a ticking version of the Tips dataset
129+
130+
# filter the tips dataset for separate lunch and dinner charts
131+
lunch_tips = tips.where("Time = `Lunch`")
132+
dinner_tips = tips.where("Time = `Dinner`")
133+
134+
# create chart that shares x axes along the row
135+
tipping_plots = dx.make_subplots(
136+
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
137+
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
138+
cols=2, shared_xaxes="rows"
139+
)
140+
```
141+
142+
## API Reference
41143
```{eval-rst}
42144
.. dhautofunction:: deephaven.plot.express.make_subplots
43145
```

plugins/plotly-express/src/deephaven/plot/express/plots/_layer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ def match_axes(
270270
# this is the base axis to match to, so matches is not added
271271
return {}
272272
if axis_index is not None:
273+
if axis_index not in matches_axes[match_axis_key]:
274+
# this is the first axis to match to, so add it
275+
matches_axes[match_axis_key][axis_index] = new_trace_axis
273276
return {"matches": matches_axes[match_axis_key][axis_index]}
274277

275278
return {}

plugins/plotly-express/src/deephaven/plot/express/plots/subplots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ def make_subplots(
357357
calculated from rows and number of figs provided if not passed
358358
but rows is.
359359
One of rows or cols should be provided if passing figs directly.
360-
shared_xaxes: "rows", "cols"/True, "all" or None depending on what axes
360+
shared_xaxes: "rows", "columns"/True, "all" or None depending on what axes
361361
should be shared
362-
shared_yaxes: "rows"/True, "cols", "all" or None depending on what axes
362+
shared_yaxes: "rows"/True, "columns", "all" or None depending on what axes
363363
should be shared
364364
grid: A grid (list of lists) of figures to draw. None can be
365365
provided in a grid entry

0 commit comments

Comments
 (0)