Skip to content

fig.add_vline fails on figure with a separate subplot containing Scatter3d #3874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
slishak opened this issue Aug 31, 2022 · 2 comments
Open
Labels
bug something broken P3 backlog

Comments

@slishak
Copy link

slishak commented Aug 31, 2022

The following code creates a 2D subplot in the left column and a 3D subplot in the right column. Adding a vertical line to the 2D subplot fails if a Scatter3d has been added to the 3D subplot.

Another bug shown in this example is that add_vline does not add any annotations if the plot is empty.

from plotly import subplots
specs = [
    [{}, {'type': 'scene', 'rowspan': 1}],
]
fig = subplots.make_subplots(rows=1, cols=2, specs=specs)

# Add dummy data 
# If both of these are commented out, fig.add_vline does nothing
# If neither are commented out, fig.add_vline raises a PlotlyKeyError
# If fig.add_scatter3d is commented out, the figure is generated successfully
fig.add_scatter(x=[0, 1], y=[0, 1], row=1, col=1)
fig.add_scatter3d(x=[0, 1], y=[0, 1], z=[0, 1], row=1, col=2)

# Add vertical line to left (2D) subplots only
fig.add_vline(x=2, col=1)  # Raises PlotlyKeyError

(Plotly version 5.9.0)

@slishak
Copy link
Author

slishak commented Aug 31, 2022

Three different behaviours for permutations of the order of the fig methods:

# Works as intended
fig.add_scatter(x=[0, 1], y=[0, 1], row=1, col=1)
fig.add_vline(x=0.5, col=1)
fig.add_scatter3d(x=[0, 1], y=[0, 1], z=[0, 1], row=1, col=2)
# Vertical line missing
fig.add_vline(x=0.5, col=1)
fig.add_scatter(x=[0, 1], y=[0, 1], row=1, col=1)
fig.add_scatter3d(x=[0, 1], y=[0, 1], z=[0, 1], row=1, col=2)
# Exception raised
fig.add_scatter3d(x=[0, 1], y=[0, 1], z=[0, 1], row=1, col=2)
fig.add_scatter(x=[0, 1], y=[0, 1], row=1, col=1)
fig.add_vline(x=0.5, col=1)

And the exception stack trace:

  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\graph_objs\_figure.py", line 997, in add_vline
    return super(Figure, self).add_vline(
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 4086, in add_vline
    self._process_multiple_axis_spanning_shapes(
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 4034, in _process_multiple_axis_spanning_shapes
    self.add_shape(
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\graph_objs\_figure.py", line 22874, in add_shape
    return self._add_annotation_like(
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 1528, in _add_annotation_like
    self._add_annotation_like(
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 1584, in _add_annotation_like
    not self._subplot_not_empty(
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 4217, in _subplot_not_empty
    for t in [
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 4221, in <listcomp>
    "x" if d[xaxiskw] is None else d[xaxiskw],
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 4704, in __getitem__
    self._raise_on_invalid_property_error(_error_to_raise=PlotlyKeyError)(
  File "C:\Users\sam\AppData\Local\Programs\Python\Python39\lib\site-packages\plotly\basedatatypes.py", line 5078, in _ret
    raise _error_to_raise(
_plotly_utils.exceptions.PlotlyKeyError: Invalid property specified for object of type plotly.graph_objs.Scatter3d: 'xaxis'

@AaronStiff AaronStiff added the bug something broken label Mar 23, 2023
@AaronStiff
Copy link
Contributor

Looks like this is related to #3424

@gvwilson gvwilson self-assigned this Jul 11, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added the P3 backlog label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

No branches or pull requests

3 participants