plotly / plotly/plotly.py

add_vline not rendering properly with secondary y-axis

Open
#3,572 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Hello,

I encountered a problem, when using add_vline with a secondary y-axis and no data on it.

plotly.py version: 5.5.0

Minimum example:

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(
    specs=[[{"secondary_y": True}]],
)

# Uncomment the line below to "fix" the problem
# fig.add_trace(go.Scatter(x=[0, 1], y=[2, 3]), secondary_y=False)
fig.add_trace(go.Scatter(x=[4, 5], y=[6, 10]), secondary_y=True)
# Change secondary_y to True to also "fix" the problem
fig.add_vline(4.5, exclude_empty_subplots=False, secondary_y=False)

image

Expected behavior:
The add_vline should a vertical line to the plot no matter if it has traces or not. How the plot looks like, when following the second comment.

Best regards
Julian

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimum example in the issue with plotly.py 5.5.0 and inspect the add_vline behavior when the primary axis has no data. Compare the result with the commented trace and secondary_y=True cases; done means the vertical line renders on the requested axis even when that axis has no traces.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.