Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09eea88

Browse files
vline etc. can be added to single plot now
without breaking previous _add_annotation_like behaviour.
1 parent 38ef1d1 commit 09eea88

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

packages/python/plotly/plotly/basedatatypes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,14 +1193,6 @@ def _add_annotation_like(
11931193
xref, yref = xaxis.replace("axis", ""), yaxis.replace("axis", "")
11941194
new_obj.update(xref=xref, yref=yref)
11951195

1196-
# xref and yref are set to the first axes if not set.
1197-
# This is so that routines that need these to be specified if row and
1198-
# col were not specified can still work (e.g., `add_vline`).
1199-
if new_obj.xref is None:
1200-
new_obj.xref = "x"
1201-
if new_obj.yref is None:
1202-
new_obj.yref = "y"
1203-
12041196
self.layout[prop_plural] += (new_obj,)
12051197

12061198
return self
@@ -3549,6 +3541,14 @@ def _process_multiple_paper_spanning_shapes(
35493541
# the new shapes that were added at the end
35503542
n_shapes_before = len(self.layout["shapes"])
35513543
self.add_shape(row=row, col=col, **shape_args, **kwargs)
3544+
if row == None and col == None:
3545+
# this was called intending to add to a single plot (and
3546+
# self.add_shape succeeded)
3547+
# however, in the case of a single plot, xref and yref are not
3548+
# specified, so we specify them here to the following routines can work
3549+
# (they need to change xref or yref to paper and change their range
3550+
# to the domain)
3551+
self.layout["shapes"][-1].update(xref="x", yref="y")
35523552
n_shapes_after = len(self.layout["shapes"])
35533553
new_shapes = tuple(
35543554
filter(

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,28 @@ def test_add_span_shape_no_empty_plot(
369369
{
370370
"type": "line",
371371
"x0": 0,
372-
"x1": 0.4,
372+
"x1": 1,
373373
"xref": "paper",
374374
"y0": 6,
375375
"y1": 6,
376376
"yref": "y",
377377
}
378378
],
379-
)
379+
),
380+
(
381+
(go.Figure.add_vline, dict(x=6)),
382+
[
383+
{
384+
"type": "line",
385+
"y0": 0,
386+
"y1": 1,
387+
"xref": "x",
388+
"x0": 6,
389+
"x1": 6,
390+
"yref": "paper",
391+
}
392+
],
393+
),
380394
],
381395
)
382396
def test_non_subplot_add_span_shape(test_input, expected, non_subplot_fig_fixture):

0 commit comments

Comments
 (0)