Sub plots
Multiple sub plots can be combined into one plot using the make_subplots
function. This function accepts multiple plot objects, and returns a single plot object. The plot objects can be any of the plot types supported by Deephaven Express. They can be arranged in a grid, or in a single row or column. The shared_xaxes
and shared_yaxes
parameters can be used to share axes between plots.
Examples
Four unique plots
Create a series of plots as subplots, all providing unique perspectives on the data of interest.
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.violin(tips, y="TotalBill", by="Day",
title="Total bill distribution by day"),
dx.pie(
tips
.count_by("Count", by=["Sex", "Smoker"])
.update_view("SmokerStatus = Smoker == `No` ? `non-smoker` : `smoker`")
.update_view("SmokerLabel = Sex + ` ` + SmokerStatus"),
names="SmokerLabel", values="Count",
title="Total bill by sex and smoking status"),
dx.bar(tips
.view(["TotalBill", "Tip", "Day"])
.avg_by("Day"),
x="Day", y=["TotalBill", "Tip"],
title="Average tip as a fraction of total bill"),
rows=2, cols=2, shared_xaxes=False, shared_yaxes=False
)
API Reference
Create subplots. Either figs and at least one of rows and cols or grid should be passed.
Returns: DeephavenFigure
The DeephavenFigure with subplots
Parameters | Type | Default | Description |
---|---|---|---|
*figs | Figure | DeephavenFigure | Figures to use. Should be used with rows and/or cols. | |
rows | int | 0 | A list of rows in the resulting subplot grid. This is calculated from cols and number of figs provided if not passed but cols is. One of rows or cols should be provided if passing figs directly. |
cols | int | 0 | A list of cols in the resulting subplot grid. This is 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 | str | bool | None | None | "rows", "cols"/True, "all" or None depending on what axes should be shared |
shared_yaxes | str | bool | None | None | "rows"/True, "cols", "all" or None depending on what axes should be shared |
grid | List[List[Figure | DeephavenFigure]] | None | None | A grid (list of lists) of figures to draw. None can be provided in a grid entry |
horizontal_spacing | float | None | None | Spacing between each column. Default 0.2 / cols |
vertical_spacing | float | None | None | Spacing between each row. Default 0.3 / rows |
column_widths | list[float] | None | None | The widths of each column. Should sum to 1. |
row_heights | list[float] | None | None | The heights of each row. Should sum to 1. |
specs | list[SubplotSpecDict] | List[List[SubplotSpecDict]] | None | None | (Default value = None) A list or grid of dicts that contain specs. An empty dictionary represents no specs, and None represents no figure, either to leave a gap on the subplots on provide room for a figure spanning multiple columns. 'l' is a float that adds left padding 'r' is a float that adds right padding 't' is a float that adds top padding 'b' is a float that adds bottom padding 'rowspan' is an int to make this figure span multiple rows 'colspan' is an int to make this figure span multiple columns |
unsafe_update_figure | Callable | <function default_callback> | An update function that takes a plotly figure as an argument and optionally returns a plotly figure. If a figure is not returned, the plotly figure passed will be assumed to be the return value. Used to add any custom changes to the underlying plotly figure. Note that the existing data traces should not be removed. This may lead to unexpected behavior if traces are modified in a way that break data mappings. |