A single plot answers one question; plotting a measurement and the quantity that drives it one above the other, sharing the same time axis, answers a better one: "when the price moved, what did volume do?" Plotly builds such multi-panel figures with make_subplots, which creates a grid of panels, each with its own pair of axes, and lets you say which trace goes in which cell and which axes line up.
The second tool is the facet: the same chart repeated for each value of a column. Express makes it one argument (facet_col="region"), and seeing whether a pattern holds in every panel is the reason to do it. Panels are numbered in a way that surprises people (the axes of the second panel are x2/y2), and the panel titles are annotations, so everything is checkable.
Implement stacked_panels(x, y_top, y_bottom, titles), facet_scatter(df, x, y, col, col_order) and panel_titles(fig). The signatures and docstrings are already in the editor.
stacked_panels(x, y_top, y_bottom, titles) returns a go.Figure made with make_subplots with 2 rows and 1 column, sharing the x axis, with titles (a pair) as the subplot titles. Row 1 holds one Scatter of (x, y_top) and row 2 one Scatter of (x, y_bottom).facet_scatter(df, x, y, col, col_order) returns a Plotly Express scatter faceted by the column col, one panel per value in col_order, left to right.panel_titles(fig) returns the text of the subplot or facet titles, in the order they appear in the figure's annotations, as a list of strings.fig.show().make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=[...]) creates the grid; fig.add_trace(trace, row=1, col=1) puts a trace in a cell.
px.scatter(..., facet_col="col", category_orders={"col": [...]}) creates the facet panels.
Subplot and facet titles are stored as annotations in fig.layout.annotations.
No results yet
Run your code to check it against the examples, or submit to run every test.