@@ -1559,6 +1559,7 @@ def _add_annotation_like(
15591559 subplot_type = refs [0 ].subplot_type ,
15601560 )
15611561 )
1562+ '''
15621563 if len(refs) == 1 and secondary_y:
15631564 raise ValueError(
15641565 """
@@ -1567,33 +1568,41 @@ def _add_annotation_like(
15671568 prop_singular=prop_singular, r=row, c=col
15681569 )
15691570 )
1571+ '''
1572+
15701573 #'''
1571- # If the new_object was created with an xref specified, the specified xref should be used otherwise assign the xref from the layout_keys
1572- if new_obj .xref == None :
1573- if secondary_y :
1574- xaxis = refs [1 ].layout_keys [0 ]
1575- else :
1576- xaxis = refs [0 ].layout_keys [0 ]
1577- xref = xaxis .replace ("axis" , "" )
1578- else :
1579- xref = new_obj .xref
1580- # If the new_object was created with an xref specified, the specified xref should be used otherwise assign the xref from the layout_keys
1581- if new_obj .yref == None :
1574+ # If the new_object was created with an yref specified, the specified yref should be used otherwise assign the xref from the layout_keys
1575+ if new_obj .yref == None or new_obj .yref == "y" :
1576+ if len (refs ) == 1 and secondary_y :
1577+ raise ValueError (
1578+ """
1579+ Cannot add {prop_singular} to secondary y-axis of subplot at position ({r}, {c})
1580+ because subplot does not have a secondary y-axis""" .format (
1581+ prop_singular = prop_singular , r = row , c = col
1582+ )
1583+ )
15821584 if secondary_y :
15831585 yaxis = refs [1 ].layout_keys [1 ]
1586+ xaxis = refs [1 ].layout_keys [0 ]
15841587 else :
15851588 yaxis = refs [0 ].layout_keys [1 ]
1589+ xaxis = refs [0 ].layout_keys [0 ]
15861590 yref = yaxis .replace ("axis" , "" )
1591+ xref = xaxis .replace ("axis" , "" )
15871592 else :
15881593 yref = new_obj .yref
1594+ xaxis = refs [0 ].layout_keys [0 ]
1595+ xref = xaxis .replace ("axis" , "" )
15891596 #'''
1597+
15901598 """
15911599 if secondary_y:
15921600 xaxis, yaxis = refs[1].layout_keys
15931601 else:
15941602 xaxis, yaxis = refs[0].layout_keys
15951603 xref, yref = xaxis.replace("axis", ""), yaxis.replace("axis", "")
15961604 """
1605+
15971606 # if exclude_empty_subplots is True, check to see if subplot is
15981607 # empty and return if it is
15991608 if exclude_empty_subplots and (
@@ -1615,6 +1624,10 @@ def _add_domain(ax_letter, new_axref):
16151624 new_obj .update (xref = xref , yref = yref )
16161625
16171626 self .layout [prop_plural ] += (new_obj ,)
1627+ # The 'new_obj.xref' and 'new_obj.yref' parameters need to be reset otherwise it
1628+ # will appear as if user supplied yref params and will force annotation to
1629+ # be on the axis of the last drawn annotation (they all end up on the same axis)
1630+ new_obj .update (xref = None , yref = None )
16181631
16191632 return self
16201633
0 commit comments