Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR contains the initial implementation of a version 4 rewrite of the
make_subplots
function.This new function is located in a new
plotly.subplots
module, and to use it the newv4_subplots
future flag must be enabled. Whenv4_subplots
is enabled, the legacyplotly.tools.make_subplots
function will delegate to `plotly.subplots.make_subplots, but otherwise the legacy function will operate unchanged for the remainder of plotly.py version 3.cc: @chriddyp @nicolaskruchten
Notable changes
The new implementation has the following notable changes.
trace types
All subplot/trace types are now supported 🎉 To accomplish this, a new 'type' property has been added to elements of the
specs
argument. For exampleThe value of
type
may be'xy'
(the default, for 2D Cartesian subplots),'scene'
(for 3D Cartesian subplots),'polar'
,'ternary'
,'geo'
, or'domain
' (for self positioning traces that don't have shared subplots). In addition, the name of any trace can be used and the subplot type for that trace will be used.For backward compatibility, the
is_3d
specs flag is still accepted. It is treated as'type': 'scene'
.Shared axes using
matching
Unlike the legacy implementation, this implementation always creates xaxis/yaxis pairs for each 2D cartesian subplot. Axis sharing (
shared_xaxes
andshared_yaxes
) is implemented not by actually sharing the same, for example, xaxis among multiple yaxes. Instead, sharing is accomplished using thematches
property introduced in plotly.js version 1.45. This significantly simplifies the subplot construction logic, and it makes it possible to support more flexible axis "sharing". Now, theshared_xaxes
/shared_yaxes
arguments may be set to 'rows', 'columns', or 'all'. Setting these values toTrue
will maintain the legacy behavior of sharing xaxes across columns and sharing yaxes across rows.Row and column titles
New
row_titles
andcolumn_titles
arguments have been added for giving titles to subplot columns and rows. These are alternatives to the existingsubplot_titles
argument for giving titles to each individual subplot. Column titles are place at the top of each column, while row titles are placed to the right of each row and rotated vertically.These are added to support faceted subplots
x_title and y_title
New arguments
x_title
andy_title
have been added to allow for the placement for a centered titles across all rows and columns. See image above for example.print_grid cleamup
The
print_grid
argument is nowFalse
by default and when it is printed is uses unicode characters to display spanned subplots in a more readable way.Before:
After:
row/column width/height cleanup
For API consistency,
column_width
has been renamedcolumn_widths
androw_width
has been renamedrow_heights
(The old args still accepted for compatibility, but they don't show up in the function signature of the docstring.In addition the behavior of
row_heights
has changed slightly forrow_width
. Now, the height specification followings the ordering specified instart_cell
. So whenstart_cell='top-left'
the row heights are specified from top to bottom, and whenstart_cell='bottom-left'
they are specified from bottom to top. The old behavior was to always treat therow_width
argument as specifying heights from bottom to top.See #1275 for the confusion this has caused.
figure.get_subplot method
A new figure method,
get_subplot
has been added for retrieving a subplot object from a figure by row/column index. Here's the docstringAmong other uses, this will make it possible for folks to construct a faceted plot with
plotly_express
and then customize the subplot properties in the resulting figure.Future flag
To activate this functionality, the
v4_subplots
(orv4
) future flag must be enabled before import plotly.Examples
Faceted subplots with all xaxes and yaxes shared, so all 6 subplots pans/zoom together.
Mixed type subplots with spanning, and
print_grid=True
to show how the spanned grid is now represented