plotly / plotly/plotly.js

full_figure_for_development giving different margins in 6.3 than in 6.2

Open
#7,632 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
18.3k
Forks
2k
Avg merge
2d 12h
Merged PRs (30d)
28

Description

I noticed that full_figure_for_development gives different margins in plotly.py 6.2 and 6.3, probably because of the plotly.js version bump from 3.0.1 to 3.1.0. Can this be considered a bug? In our use case, we read and use these values to update figure.layout.height, because we want to ensure a fixed height of the plot area.

Consider this plotly.py code:

import plotly.graph_objects as go

figure_dict = {
  "data": [
    {
      "x": ["A", "B", "C", "D"],
      "y": [100, 200, 150, 300],
      "type": "bar"
    }
  ],
  "layout": {
    "margin": {
      "b": 40,
      "l": 0,
      "r": 0,
      "t": 0
    },
    "yaxis": {
      "tickfont": {
        "size": 19
      },
      "ticklabelposition": "inside top",
      "ticklen": 10
    }
  }
}

figure = go.Figure(data=figure_dict["data"], layout=figure_dict["layout"])
fffd = figure.full_figure_for_development()

print(fffd.layout.computed["margin"])
Output for 6.2.0:

{'b': 105, 'l': 0, 'r': 0, 't': 4}

Output for 6.3.0:

{'b': 105, 'l': 0, 'r': 0, 't': 0}

With this second example, also margin.b differs:

import plotly.graph_objects as go

figure_dict = {
    "data": [
        {
            "x": [
                "A",
                "B",
                "C",
                "D"
            ],
            "y": [
                100,
                200,
                150,
                190
            ],
            "type": "bar"
        }
    ],
    "layout": {
        "yaxis": {
            "automargin": "height",
            "ticklabelposition": "inside top",
            "insiderange": [
                0,
                250
            ]
        },
        "autosize": True,
        "legend": {
            "orientation": "v",
            "x": 0.05,
            "y": -0.1,
            "yanchor": "top"
        },
        "margin": {
            "autoexpand": True,
            "b": 40,
            "l": 0,
            "r": 0,
            "t": 0
        },
        "showlegend": True
    }
}

figure = go.Figure(data=figure_dict["data"], layout=figure_dict["layout"])
fffd = figure.full_figure_for_development()

print(fffd.layout.computed["margin"])
Output for 6.2.0:

{'b': 70, 'l': 0, 'r': 0, 't': 17}

Output for 6.3.0:

{'b': 72, 'l': 0, 'r': 0, 't': 0}

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

Reproduce both examples with plotly.js 3.0.1 and 3.1.0 through plotly.py's full_figure_for_development(), then investigate how the computed margin values are produced. Done means the version-related margin differences are explained and the expected behavior is covered by a regression check.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.