Skip to content
Merged
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
104 changes: 103 additions & 1 deletion plugins/plotly-express/docs/sub-plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,110 @@ tipping_plots = dx.make_subplots(

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

## API Reference
### Share Axes

Share axes between plots with the `shared_xaxes` and `shared_yaxes` parameters.

#### Share All Axes

When `shared_xaxes` or `shared_yaxes` is set to `"all"`, all axes of the same type are shared.
When one axis is adjusted, all axes are adjusted to match.

```python order=tipping_plots,lunch_tips,dinner_tips
import deephaven.plot.express as dx
tips = dx.data.tips() # import a ticking version of the Tips dataset

# filter the tips dataset for separate lunch and dinner charts
lunch_tips = tips.where("Time = `Lunch`")
dinner_tips = tips.where("Time = `Dinner`")

# create chart that shares all axes
tipping_plots = dx.make_subplots(
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
rows=2, shared_yaxes="all", shared_xaxes="all"
)
```

#### Share Y Axes

When `shared_yaxis` is set to `True`, all y axes are shared along the same row.
When one y-axis is adjusted, all axes along the same row are adjusted to match.

```python order=tipping_plots,lunch_tips,dinner_tips
import deephaven.plot.express as dx
tips = dx.data.tips() # import a ticking version of the Tips dataset

# filter the tips dataset for separate lunch and dinner charts
lunch_tips = tips.where("Time = `Lunch`")
dinner_tips = tips.where("Time = `Dinner`")

# create chart that shares y axes along the row
tipping_plots = dx.make_subplots(
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
cols=2, shared_yaxes=True
)
```

To share the y axes along the same column, set `shared_yaxes` to `"columns"`.

```python order=tipping_plots,lunch_tips,dinner_tips
import deephaven.plot.express as dx
tips = dx.data.tips() # import a ticking version of the Tips dataset

# filter the tips dataset for separate lunch and dinner charts
lunch_tips = tips.where("Time = `Lunch`")
dinner_tips = tips.where("Time = `Dinner`")

# create chart that shares y axes along the column
tipping_plots = dx.make_subplots(
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
rows=2, shared_yaxes="columns"
)
```

#### Share X Axes

When `shared_xaxis` is set to `True`, all x axes are shared along the same column.
When one x-axis is adjusted, all axes along the same column are adjusted to match.

```python order=tipping_plots,lunch_tips,dinner_tips
import deephaven.plot.express as dx
tips = dx.data.tips() # import a ticking version of the Tips dataset

# filter the tips dataset for separate lunch and dinner charts
lunch_tips = tips.where("Time = `Lunch`")
dinner_tips = tips.where("Time = `Dinner`")

# create chart that shares x axes along the column
tipping_plots = dx.make_subplots(
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
rows=2, shared_xaxes=True
)
```

To share the x axes along the same column, set `shared_yaxes` to `"columns"`.

```python order=tipping_plots,lunch_tips,dinner_tips
import deephaven.plot.express as dx
tips = dx.data.tips() # import a ticking version of the Tips dataset

# filter the tips dataset for separate lunch and dinner charts
lunch_tips = tips.where("Time = `Lunch`")
dinner_tips = tips.where("Time = `Dinner`")

# create chart that shares x axes along the row
tipping_plots = dx.make_subplots(
dx.scatter(lunch_tips, x="TotalBill", y="Tip", labels={"Tip": "Lunch Tips"}),
dx.scatter(dinner_tips, x="TotalBill", y="Tip", labels={"Tip": "Dinner Tips"}),
cols=2, shared_xaxes="rows"
)
```

## API Reference
```{eval-rst}
.. dhautofunction:: deephaven.plot.express.make_subplots
```
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def match_axes(
# this is the base axis to match to, so matches is not added
return {}
if axis_index is not None:
if axis_index not in matches_axes[match_axis_key]:
# this is the first axis to match to, so add it
matches_axes[match_axis_key][axis_index] = new_trace_axis
return {"matches": matches_axes[match_axis_key][axis_index]}

return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ def make_subplots(
calculated from rows and number of figs provided if not passed
but rows is.
One of rows or cols should be provided if passing figs directly.
shared_xaxes: "rows", "cols"/True, "all" or None depending on what axes
shared_xaxes: "rows", "columns"/True, "all" or None depending on what axes
should be shared
shared_yaxes: "rows"/True, "cols", "all" or None depending on what axes
shared_yaxes: "rows"/True, "columns", "all" or None depending on what axes
should be shared
grid: A grid (list of lists) of figures to draw. None can be
provided in a grid entry
Expand Down
Loading
Loading