Skip to content

write_image doesn't seem to respect width/height #378

Open

Description

@DanielYang59

Thanks for working on this helpful package again. I guess very likely similar to #12, but it seems to appear for our case:

  • kaleido: 1.0.0, plotly: 6.2.0
  • macos 15.6 (ARM64)
  • Python 3.10.18
import plotly.graph_objects as go

fig = go.Figure(go.Bar(x=["A", "B"], y=[1, 2]))
fig.update_layout(width=1200, height=300)

fig.write_image("out.svg")

Saved image (obviously not 1200:300):

Image

And the following as suggested in #12 seems to fix:

plotly.io.defaults.default_width = None
plotly.io.defaults.default_height = None

Activity

  1. added
    bugsomething broken
    P2needed for current cycle
    on Aug 11, 2025
  2. ayjayt commented on Aug 11, 2025

    @ayjayt
    Collaborator

    @emilykl

    If it's okay with you, I can send a PR to remove the default width from plotly.io, which overrides kaleido's default width logic:

    This is the kaleido logic:

    def _get_figure_dimensions(layout, width, height):
        # Compute image width / height with fallbacks
        width = (
            width
            or layout.get("width")
            or layout.get("template", {}).get("layout", {}).get("width")
            or DEFAULT_WIDTH
        )
        height = (
            height
            or layout.get("height")
            or layout.get("template", {}).get("layout", {}).get("height")
            or DEFAULT_HEIGHT
        )
        return width, height
    

    Note that kaleido will fall back to the exact same DEFAULT_WIDTH/DEFAULT_HEIGHT (500/700) as plotly.io.

  3. added and removed on Aug 11, 2025
  4. ayjayt commented on Aug 12, 2025

    @ayjayt
    Collaborator

    per meeting, I will submit fix to plotly.io

  5. ayjayt commented on Aug 13, 2025

    @ayjayt
    Collaborator
  6. DanielYang59 commented on Aug 18, 2025

    @DanielYang59
    Author

    Great thanks for quickly fix this ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2needed for current cyclebugsomething broken

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions