Skip to content

Commit d5bce9a

Browse files
committed
Update test and also round other values
1 parent 6936fd3 commit d5bce9a

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

Diff for: packages/python/plotly/plotly/_subplots.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):
671671
# Loop through specs -- (r, c) <-> (row, col)
672672
for r, spec_row in enumerate(specs):
673673
for c, spec in enumerate(spec_row):
674-
675674
if spec is None: # skip over None cells
676675
continue
677676

@@ -703,6 +702,16 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):
703702
y_s = grid[r_spanned][c][1] + spec["b"]
704703
y_e = grid[r][c][1] + heights[-1 - r] - spec["t"]
705704

705+
if y_s < 0.0:
706+
# round for values very close to one
707+
# handles some floating point errors
708+
if y_s > -0.01:
709+
y_s = 0.0
710+
else:
711+
raise Exception(
712+
"A combination of the 'b' values, heights, and "
713+
"number of subplots too large for this subplot grid."
714+
)
706715
if y_s > 1.0:
707716
# round for values very close to one
708717
# handles some floating point errors
@@ -713,6 +722,16 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):
713722
"A combination of the 'b' values, heights, and "
714723
"number of subplots too large for this subplot grid."
715724
)
725+
726+
if y_e < 0.0:
727+
if y_e > -0.01:
728+
y_e = 0.0
729+
else:
730+
raise Exception(
731+
"A combination of the 't' values, heights, and "
732+
"number of subplots too large for this subplot grid."
733+
)
734+
716735
if y_e > 1.0:
717736
if y_e < 1.01:
718737
y_e = 1.0
@@ -746,7 +765,6 @@ def _check_hv_spacing(dimsize, spacing, name, dimvarname, dimname):
746765
insets_ref = [None for inset in range(len(insets))] if insets else None
747766
if insets:
748767
for i_inset, inset in enumerate(insets):
749-
750768
r = inset["cell"][0] - 1
751769
c = inset["cell"][1] - 1
752770

@@ -1072,7 +1090,6 @@ def _subplot_type_for_trace_type(trace_type):
10721090

10731091

10741092
def _validate_coerce_subplot_type(subplot_type):
1075-
10761093
# Lowercase subplot_type
10771094
orig_subplot_type = subplot_type
10781095
subplot_type = subplot_type.lower()
@@ -1220,7 +1237,6 @@ def _build_subplot_title_annotations(
12201237

12211238

12221239
def _build_grid_str(specs, grid_ref, insets, insets_ref, row_seq):
1223-
12241240
# Compute rows and columns
12251241
rows = len(specs)
12261242
cols = len(specs[0])
@@ -1277,7 +1293,6 @@ def _pad(s, cell_len=cell_len):
12771293
# Loop through specs, fill in _tmp
12781294
for r, spec_row in enumerate(specs):
12791295
for c, spec in enumerate(spec_row):
1280-
12811296
ref = grid_ref[r][c]
12821297
if ref is None:
12831298
if _tmp[r][c] == "":
@@ -1359,7 +1374,6 @@ def _pad(s, cell_len=cell_len):
13591374

13601375

13611376
def _set_trace_grid_reference(trace, layout, grid_ref, row, col, secondary_y=False):
1362-
13631377
if row <= 0:
13641378
raise Exception(
13651379
"Row value is out of range. " "Note: the starting cell is (1, 1)"
@@ -1481,7 +1495,6 @@ def _get_grid_subplot(fig, row, col, secondary_y=False):
14811495

14821496

14831497
def _get_subplot_ref_for_trace(trace):
1484-
14851498
if "domain" in trace:
14861499
return SubplotRef(
14871500
subplot_type="domain",

Diff for: packages/python/plotly/plotly/tests/test_core/test_subplots/test_make_subplots.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ def test_specs_rounding_rounds_down(self):
668668
for _ in range(n_subplots):
669669
specs.append([{"b": padding_size / 2.0, "t": padding_size / 2.0}])
670670

671-
fig = tls.make_subplots(rows=n_subplots, specs=specs)
671+
fig = subplots.make_subplots(rows=n_subplots, specs=specs)
672672
self.assertTrue(
673673
all(
674674
fig.layout[f"yaxis{i if i > 1 else ''}"]["domain"][0] <= 1.0

0 commit comments

Comments
 (0)