plotly / plotly/plotly.py

make the `._has_subplots` method from `go.Figure` accessible

Open
#4,062 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

In some cases, when writings callbacks that only update a subplot of a Figure, it is useful to know if the figure will accept an append_trace to a specific location, or if add_trace should be used instead.

I use this workaround (using a try/except isn't great):

    if fig._has_subplots():
        fig.append_trace(trace, 1, 1)
    else:
        _ = fig.add_trace(trace)

If I only use fig.append_trace(trace, 1, 1), I get Exception: In order to reference traces by row and column, you must first use plotly.tools.make_subplots to create the figure with a subplot grid.

If I only use fig.add_trace(trace), the layout gets messed up.

Could it be possible to make this method public?

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

Inspect go.Figure's _has_subplots implementation and the public Figure API around append_trace, add_trace, and make_subplots. The work is done when callers can use a public check to determine whether row-and-column trace references are valid without relying on a try/except workaround, while preserving existing subplot behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.