@@ -1563,13 +1563,28 @@ def _add_annotation_like(
1563
1563
raise ValueError (
1564
1564
"""
1565
1565
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
+ )
1567
1569
)
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" , "" )
1570
1586
else :
1571
- xaxis , yaxis = refs [0 ].layout_keys
1572
- xref , yref = xaxis .replace ("axis" , "" ), yaxis .replace ("axis" , "" )
1587
+ yref = new_obj .yref
1573
1588
# if exclude_empty_subplots is True, check to see if subplot is
1574
1589
# empty and return if it is
1575
1590
if exclude_empty_subplots and (
0 commit comments