|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
3 | 3 | import plotly.graph_objects as go
|
| 4 | +from plotly.subplots import make_subplots |
4 | 5 | from plotly.tests.utils import TestCaseNoTemplate
|
| 6 | +import pytest |
5 | 7 |
|
6 | 8 |
|
7 | 9 | class FigureTest(TestCaseNoTemplate):
|
@@ -199,3 +201,21 @@ def test_update_overwrite_data(self):
|
199 | 201 | fig.to_plotly_json()["data"],
|
200 | 202 | [{"type": "scatter", "y": [1, 3, 2], "line": {"color": "yellow"}}],
|
201 | 203 | )
|
| 204 | + |
| 205 | + |
| 206 | +def test_set_subplots(): |
| 207 | + # Test that it works the same as make_subplots for a simple call |
| 208 | + fig0 = go.Figure() |
| 209 | + fig0_sp = make_subplots(2, 2) |
| 210 | + fig0.set_subplots(2, 2) |
| 211 | + assert fig0.layout == fig0_sp.layout |
| 212 | + # Test that it accepts the same arguments as make_subplots |
| 213 | + fig1 = go.Figure() |
| 214 | + fig1.set_subplots(rows=2, cols=2, horizontal_spacing=0.25, vertical_spacing=0.1) |
| 215 | + fig1_sp = make_subplots( |
| 216 | + rows=2, cols=2, horizontal_spacing=0.25, vertical_spacing=0.1 |
| 217 | + ) |
| 218 | + assert fig1.layout == fig1_sp.layout |
| 219 | + # Test that calling on a figure that already has subplots throws an error. |
| 220 | + with pytest.raises(ValueError, match=r"^This figure already has subplots\.$"): |
| 221 | + fig1.set_subplots(2, 3) |
0 commit comments