|
9 | 9 | from contextlib import contextmanager
|
10 | 10 | from copy import deepcopy, copy
|
11 | 11 |
|
| 12 | +from plotly.subplots import _set_trace_grid_reference, _get_grid_subplot |
12 | 13 | from .optional_imports import get_module
|
13 | 14 |
|
14 | 15 | from _plotly_utils.basevalidators import (
|
@@ -1237,10 +1238,15 @@ def _set_trace_grid_position(self, trace, row, col):
|
1237 | 1238 | try:
|
1238 | 1239 | grid_ref = self._grid_ref
|
1239 | 1240 | except AttributeError:
|
1240 |
| - raise Exception("In order to use Figure.append_trace, " |
| 1241 | + raise Exception("In order to reference traces by row and column, " |
1241 | 1242 | "you must first use "
|
1242 | 1243 | "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 | + |
1244 | 1250 | if row <= 0:
|
1245 | 1251 | raise Exception("Row value is out of range. "
|
1246 | 1252 | "Note: the starting cell is (1, 1)")
|
@@ -1271,6 +1277,38 @@ def _set_trace_grid_position(self, trace, row, col):
|
1271 | 1277 | trace['xaxis'] = ref[0]
|
1272 | 1278 | trace['yaxis'] = ref[1]
|
1273 | 1279 |
|
| 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 | + |
1274 | 1312 | # Child property operations
|
1275 | 1313 | # -------------------------
|
1276 | 1314 | def _get_child_props(self, child):
|
|
0 commit comments