Thanks to visit codestin.com
Credit goes to github.com

Skip to content

full_figure_for_development giving different margins in 6.3 than in 6.2 #7632

@my-tien

Description

@my-tien

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions