Skip to content

Commit f92dc6e

Browse files
committed
added comments and cleaned up code
1 parent d95d8ee commit f92dc6e

File tree

2 files changed

+13
-34
lines changed

2 files changed

+13
-34
lines changed

packages/python/plotly/plotly/basedatatypes.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,19 +1559,8 @@ def _add_annotation_like(
15591559
subplot_type=refs[0].subplot_type,
15601560
)
15611561
)
1562-
'''
1563-
if len(refs) == 1 and secondary_y:
1564-
raise ValueError(
1565-
"""
1566-
Cannot add {prop_singular} to secondary y-axis of subplot at position ({r}, {c})
1567-
because subplot does not have a secondary y-axis""".format(
1568-
prop_singular=prop_singular, r=row, c=col
1569-
)
1570-
)
1571-
'''
15721562

1573-
#'''
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
1563+
# If the new_object was created with an yref specified, the specified yref should be used otherwise assign the xref and yref from the layout_keys
15751564
if new_obj.yref == None or new_obj.yref == "y":
15761565
if len(refs) == 1 and secondary_y:
15771566
raise ValueError(
@@ -1582,27 +1571,14 @@ def _add_annotation_like(
15821571
)
15831572
)
15841573
if secondary_y:
1585-
yaxis = refs[1].layout_keys[1]
1586-
xaxis = refs[1].layout_keys[0]
1574+
xaxis, yaxis = refs[1].layout_keys
15871575
else:
1588-
yaxis = refs[0].layout_keys[1]
1589-
xaxis = refs[0].layout_keys[0]
1590-
yref = yaxis.replace("axis", "")
1591-
xref = xaxis.replace("axis", "")
1576+
xaxis, yaxis = refs[0].layout_keys
1577+
xref, yref = xaxis.replace("axis", ""), yaxis.replace("axis", "")
15921578
else:
15931579
yref = new_obj.yref
15941580
xaxis = refs[0].layout_keys[0]
15951581
xref = xaxis.replace("axis", "")
1596-
#'''
1597-
1598-
"""
1599-
if secondary_y:
1600-
xaxis, yaxis = refs[1].layout_keys
1601-
else:
1602-
xaxis, yaxis = refs[0].layout_keys
1603-
xref, yref = xaxis.replace("axis", ""), yaxis.replace("axis", "")
1604-
"""
1605-
16061582
# if exclude_empty_subplots is True, check to see if subplot is
16071583
# empty and return if it is
16081584
if exclude_empty_subplots and (
@@ -1625,8 +1601,9 @@ def _add_domain(ax_letter, new_axref):
16251601

16261602
self.layout[prop_plural] += (new_obj,)
16271603
# 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)
1604+
# will appear as if user supplied yref params when looping through subplots and
1605+
# will force annotation to be on the axis of the last drawn annotation
1606+
# i.e. they all end up on the same axis.
16301607
new_obj.update(xref=None, yref=None)
16311608

16321609
return self
@@ -4084,7 +4061,7 @@ def _process_multiple_axis_spanning_shapes(
40844061
# self.add_{layout_obj} succeeded)
40854062
# however, in the case of a single plot, xref and yref MAY not be
40864063
# specified, IF they are not specified we specify them here so the following routines can work
4087-
# (they need to append " domain" to xref or yref)
4064+
# (they need to append " domain" to xref or yref). If they are specified, we leave them alone.
40884065
if self.layout[layout_obj][-1].xref == None:
40894066
self.layout[layout_obj][-1].update(xref="x")
40904067
# self.layout[layout_obj][-1].update(xref="x")

packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_annotations.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,19 @@ def test_supplied_yref_on_multi_plot_subplot():
388388
shared_yaxes=False,
389389
specs=[[{"secondary_y": True}, {"secondary_y": True}]],
390390
)
391+
### Add traces to the first subplot
391392
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3]), row=1, col=1)
392393
fig.add_trace(
393394
go.Scatter(x=[1, 2, 3], y=[3, 2, 1], yaxis="y2"), row=1, col=1, secondary_y=True
394395
)
396+
### Add traces to the second subplot
395397
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], yaxis="y"), row=1, col=2)
396398
fig.add_trace(
397399
go.Scatter(x=[1, 2, 3], y=[1, 1, 2], yaxis="y2"), row=1, col=2, secondary_y=True
398400
)
399-
# add a horizontal line on both subplots secondary y.
400-
# When using the subplots.make_subplots() method yref parameter should not be supplied to add_hline()
401-
# Instead Secondary_y MUST be True to plot on secondary y
401+
# add a horizontal line on both subplots on their respective secondary y.
402+
# When using the subplots.make_subplots() method yref parameter should NOT be supplied per docstring instructions.
403+
# Instead secondary_y specs and secondary_y parameter MUST be True to plot on secondary y
402404
fig.add_hline(y=2, row=1, col=1, secondary_y=True)
403405
fig.add_hline(y=1, row=1, col=2, secondary_y=True)
404406
assert fig.layout["shapes"][0]["yref"] == "y2"

0 commit comments

Comments
 (0)