Skip to content

Commit cc94803

Browse files
committed
fixed bug for issue plotly#3755 when the figure object contains subplots
1 parent 956ab2c commit cc94803

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

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

+20-5
Original file line numberDiff line numberDiff line change
@@ -1563,13 +1563,28 @@ def _add_annotation_like(
15631563
raise ValueError(
15641564
"""
15651565
Cannot add {prop_singular} to secondary y-axis of subplot at position ({r}, {c})
1566-
because subplot does not have a secondary y-axis"""
1566+
because subplot does not have a secondary y-axis""".format(
1567+
prop_singular=prop_singular, r=row, c=col
1568+
)
15671569
)
1568-
if secondary_y:
1569-
xaxis, yaxis = refs[1].layout_keys
1570+
# If the new_object was created with an xref specified, the specified xref should be used otherwise assign the xref from the layout_keys
1571+
if new_obj.xref is None:
1572+
if secondary_y:
1573+
xaxis = refs[1].layout_keys[0]
1574+
else:
1575+
xaxis = refs[0].layout_keys[0]
1576+
xref = xaxis.replace("axis", "")
1577+
else:
1578+
xref = new_obj.xref
1579+
# If the new_object was created with an xref specified, the specified xref should be used otherwise assign the xref from the layout_keys
1580+
if new_obj.yref is None:
1581+
if secondary_y:
1582+
yaxis = refs[1].layout_keys[1]
1583+
else:
1584+
yaxis = refs[0].layout_keys[1]
1585+
yref = yaxis.replace("axis", "")
15701586
else:
1571-
xaxis, yaxis = refs[0].layout_keys
1572-
xref, yref = xaxis.replace("axis", ""), yaxis.replace("axis", "")
1587+
yref = new_obj.yref
15731588
# if exclude_empty_subplots is True, check to see if subplot is
15741589
# empty and return if it is
15751590
if exclude_empty_subplots and (

0 commit comments

Comments
 (0)