@@ -1559,6 +1559,7 @@ def _add_annotation_like(
1559
1559
subplot_type = refs [0 ].subplot_type ,
1560
1560
)
1561
1561
)
1562
+ '''
1562
1563
if len(refs) == 1 and secondary_y:
1563
1564
raise ValueError(
1564
1565
"""
@@ -1567,33 +1568,41 @@ def _add_annotation_like(
1567
1568
prop_singular=prop_singular, r=row, c=col
1568
1569
)
1569
1570
)
1571
+ '''
1572
+
1570
1573
#'''
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
+ )
1582
1584
if secondary_y :
1583
1585
yaxis = refs [1 ].layout_keys [1 ]
1586
+ xaxis = refs [1 ].layout_keys [0 ]
1584
1587
else :
1585
1588
yaxis = refs [0 ].layout_keys [1 ]
1589
+ xaxis = refs [0 ].layout_keys [0 ]
1586
1590
yref = yaxis .replace ("axis" , "" )
1591
+ xref = xaxis .replace ("axis" , "" )
1587
1592
else :
1588
1593
yref = new_obj .yref
1594
+ xaxis = refs [0 ].layout_keys [0 ]
1595
+ xref = xaxis .replace ("axis" , "" )
1589
1596
#'''
1597
+
1590
1598
"""
1591
1599
if secondary_y:
1592
1600
xaxis, yaxis = refs[1].layout_keys
1593
1601
else:
1594
1602
xaxis, yaxis = refs[0].layout_keys
1595
1603
xref, yref = xaxis.replace("axis", ""), yaxis.replace("axis", "")
1596
1604
"""
1605
+
1597
1606
# if exclude_empty_subplots is True, check to see if subplot is
1598
1607
# empty and return if it is
1599
1608
if exclude_empty_subplots and (
@@ -1615,6 +1624,10 @@ def _add_domain(ax_letter, new_axref):
1615
1624
new_obj .update (xref = xref , yref = yref )
1616
1625
1617
1626
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 )
1618
1631
1619
1632
return self
1620
1633
0 commit comments