Skip to content

Commit 4b78d55

Browse files
authored
Version 4 make_subplots (#1528)
* Added plotly.subplots.make_subplots for use with v4_subplots future flag. * Added figure.get_subplot() method to retrieve subplot objects * print_grid=False by default in v4_subplots future mode * Allow subplot types to be specified using trace names
1 parent eeb0ac4 commit 4b78d55

File tree

6 files changed

+3546
-4
lines changed

6 files changed

+3546
-4
lines changed

_plotly_future_/v4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from __future__ import absolute_import
22
from _plotly_future_ import (
33
renderer_defaults, template_defaults, extract_chart_studio,
4-
remove_deprecations)
4+
remove_deprecations, v4_subplots)

_plotly_future_/v4_subplots.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from __future__ import absolute_import
2+
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3+
4+
_assert_plotly_not_imported()
5+
_future_flags.add('v4_subplots')

plotly/basedatatypes.py

+40-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from contextlib import contextmanager
1010
from copy import deepcopy, copy
1111

12+
from plotly.subplots import _set_trace_grid_reference, _get_grid_subplot
1213
from .optional_imports import get_module
1314

1415
from _plotly_utils.basevalidators import (
@@ -1237,10 +1238,15 @@ def _set_trace_grid_position(self, trace, row, col):
12371238
try:
12381239
grid_ref = self._grid_ref
12391240
except AttributeError:
1240-
raise Exception("In order to use Figure.append_trace, "
1241+
raise Exception("In order to reference traces by row and column, "
12411242
"you must first use "
12421243
"plotly.tools.make_subplots "
1243-
"to create a subplot grid.")
1244+
"to create the figure with a subplot grid.")
1245+
from _plotly_future_ import _future_flags
1246+
if 'v4_subplots' in _future_flags:
1247+
return _set_trace_grid_reference(
1248+
trace, self.layout, grid_ref, row, col)
1249+
12441250
if row <= 0:
12451251
raise Exception("Row value is out of range. "
12461252
"Note: the starting cell is (1, 1)")
@@ -1271,6 +1277,38 @@ def _set_trace_grid_position(self, trace, row, col):
12711277
trace['xaxis'] = ref[0]
12721278
trace['yaxis'] = ref[1]
12731279

1280+
def get_subplot(self, row, col):
1281+
"""
1282+
Return an object representing the subplot at the specified row
1283+
and column. May only be used on Figures created using
1284+
plotly.tools.make_subplots
1285+
1286+
Parameters
1287+
----------
1288+
row: int
1289+
1-based index of subplot row
1290+
col: int
1291+
1-based index of subplot column
1292+
1293+
Returns
1294+
-------
1295+
subplot
1296+
* None: if subplot is empty
1297+
* plotly.graph_objs.layout.Scene: if subplot type is 'scene'
1298+
* plotly.graph_objs.layout.Polar: if subplot type is 'polar'
1299+
* plotly.graph_objs.layout.Ternary: if subplot type is 'ternary'
1300+
* plotly.graph_objs.layout.Mapbox: if subplot type is 'ternary'
1301+
* SubplotDomain namedtuple with `x` and `y` fields:
1302+
if subplot type is 'domain'.
1303+
- x: length 2 list of the subplot start and stop width
1304+
- y: length 2 list of the subplot start and stop height
1305+
* SubplotXY namedtuple with `xaxis` and `yaxis` fields:
1306+
if subplot type is 'xy'.
1307+
- xaxis: plotly.graph_objs.layout.XAxis instance for subplot
1308+
- yaxis: plotly.graph_objs.layout.YAxis instance for subplot
1309+
"""
1310+
return _get_grid_subplot(self, row, col)
1311+
12741312
# Child property operations
12751313
# -------------------------
12761314
def _get_child_props(self, child):

0 commit comments

Comments
 (0)