← 返回首页
Fix add hline not working for make_subplot if not populated by Erikp15 · Pull Request #5254 · plotly/plotly.py · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Fix add hline not working for make_subplot if not populated#5254

Open
Erikp15 wants to merge 11 commits into
plotly:mainfrom
Erikp15:fix-add_hline-not-working
Open

Fix add hline not working for make_subplot if not populated#5254
Erikp15 wants to merge 11 commits into
plotly:mainfrom
Erikp15:fix-add_hline-not-working

Conversation

Copy link
Copy Markdown

Erikp15 commented Jun 27, 2025
edited
Loading

This is a proposal fix for issue #5136
I first reproduced the issue and created two unit tests, test_add_hline_empty_subplots.py and test_hline_subplots_bug.py, that check if the bug is resolved. Then I implemented the fix (outlined below), which passed both of the new unit tests, and in the process, no old tests were broken.

Root cause

add_shape() is called with exclude_empty_subplots=True. For a fresh make_subplots figure, every subplot is flagged empty, so the h/v line shape is filtered out and never appears, even after traces are later added.

Fix overview

When add_hline/add_vline are invoked and the figure contains no traces (len(self.data)==0), the code now disables the exclude empty subplots logic before delegating to add_shape, allowing the shape to be created and later displayed once data is added.

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the code generator and not the generated files.
  • I have added tests or modified existing tests.
  • For a new feature, I have added documentation examples (please see the doc checklist as well).
  • I have added a CHANGELOG entry if changing anything substantial.
  • For a new feature or a change in behavior, I have updated the relevant docstrings in the code.

gvwilson self-assigned this Jul 3, 2025
gvwilson added P1 needed for current cycle community community contribution fix fixes something broken labels Jul 3, 2025
Copy link
Copy Markdown
Author

Erikp15 commented Jul 12, 2025

Hi @gvwilson , just checking in to see if there's anything else needed from my end on this PR. Happy to make any changes if needed.

Copy link
Copy Markdown
Contributor

emilykl commented Oct 31, 2025

Hi @Erikp15, it seems to me that the exclude_empty_subplots argument is working as intended (i.e., it indeed does not draw the hline if the subplot is empty), so I'm not sure we want to change that behavior.

What I would recommend, if you don't want to exclude empty subplots, is to pass exclude_empty_subplots=False to add_hline() — would that work for you?

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community community contribution fix fixes something broken P1 needed for current cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Footer

© 2026 GitHub, Inc.