Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions plotly/_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,25 +1445,21 @@ def _get_grid_subplot(fig, row, col, secondary_y=False):
cols = len(grid_ref[0])

# Validate row
if not isinstance(row, int) or row < 1 or rows < row:
if not isinstance(row, int) or not (1 <= row <= rows):
raise ValueError(
"""
f"""
The row argument to get_subplot must be an integer where 1 <= row <= {rows}
Received value of type {typ}: {val}""".format(
rows=rows, typ=type(row), val=repr(row)
)
Received value of type {type(row)}: {repr(row)}"""
)

if not isinstance(col, int) or col < 1 or cols < col:
if not isinstance(col, int) or not (1 <= col <= cols):
raise ValueError(
"""
f"""
The col argument to get_subplot must be an integer where 1 <= row <= {cols}
Received value of type {typ}: {val}""".format(
cols=cols, typ=type(col), val=repr(col)
)
Received value of type {type(col)}: {repr(col)}"""
)

subplot_refs = fig._grid_ref[row - 1][col - 1]
subplot_refs = grid_ref[row - 1][col - 1]
if not subplot_refs:
return None

Expand All @@ -1475,20 +1471,25 @@ def _get_grid_subplot(fig, row, col, secondary_y=False):
else:
layout_keys = subplot_refs[0].layout_keys

if len(layout_keys) == 0:
len_layout_keys = len(layout_keys)
if len_layout_keys == 0:
# Direct domain dict
return SubplotDomain(**subplot_refs[0].trace_kwargs["domain"])
elif len(layout_keys) == 1:
return fig.layout[layout_keys[0]]
elif len(layout_keys) == 2:
elif len_layout_keys == 1:
# Single axis
layout = fig.layout # cache attribute
return layout[layout_keys[0]]
elif len_layout_keys == 2:
# X/Y axes pair
layout = fig.layout
return SubplotXY(
xaxis=fig.layout[layout_keys[0]], yaxis=fig.layout[layout_keys[1]]
xaxis=layout[layout_keys[0]],
yaxis=layout[layout_keys[1]]
)
else:
raise ValueError(
"""
Unexpected subplot type with layout_keys of {}""".format(
layout_keys
)
f"""
Unexpected subplot type with layout_keys of {layout_keys}"""
)


Expand Down