-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Background
plotly.py has a system for building figures with subplots that predates the plotly.js layout.grid system for subplots. I would like to replace this custom subplot system with layout.grid to reduce complexity inside plotly.py and add support for all trace types (plotly.py's system only supports Cartesian subplot types). This transition will also make the integration of px into plotly.py much smoother.
Needs
As far as I can tell, there are two features that are implemented in plotly.py's make_subplots function that are not supported by layout.grid.
The first two are both demonstrated in this example https://plot.ly/python/subplots/#custom-sized-subplot-with-subplot-titles.
- Spanned subplots:
make_subplotsallows individual axes to span multiple subplot grid entries - Subplot titles:
make_subplotshas a system for positioning text annotations as titles for individual subplots - column/row widths:
make_subplotssupportscolumn_widthandrow_widtharrays to support non-uniform widths of the rows and columns in the grid. - insets:
make_subplotssupports the specification of insets. TBH I'm not really sure how this works and I don't know if there are any examples of this outside of the docstring. And this might not be something that makes sense to support inlayout.grid. Here's the docstring
insets (kwarg, list of dictionaries):
Inset specifications.
- Each item in 'insets' is a dictionary.
The available keys are:
* cell (tuple, default=(1,1)): (row, col) index of the
subplot cell to overlay inset axes onto.
* is_3d (boolean, default=False): flag for 3d scenes
* l (float, default=0.0): padding left of inset
in fraction of cell width
* w (float or 'to_end', default='to_end') inset width
in fraction of cell width ('to_end': to cell right edge)
* b (float, default=0.0): padding bottom of inset
in fraction of cell height
* h (float or 'to_end', default='to_end') inset height
in fraction of cell height ('to_end': to cell top edge)
API ideas
To kick things off, here's a idea for a potential plotly.js API
- We could add
layout.grid.rowspanandlayout.grid.colspanproperties that may optionally be set to 2D arrays of integers. So the example above would have a acolspanproperty of
[[1, 1],
[2, 0]]
which would imply a grid.subplots property of
[['xy' , 'x2y2'],
['x3y3', null]]
- We could add a
grid.titlesproperty that is a 2D array of title strings. So the example above would have agrid.titlesproperty of
[['First Subplot', 'Second Subplot'],
['Third Subplot' , null]]
- We could add
grid.widthsandgrid.heightsproperties that would be 1D arrays of numbers. We could internally normalize each array and use the elements to determine the width/height of each column/row.