Skip to content

Fix pio.write_images ignoring layout width and height - #5784

Open
breken-ai wants to merge 2 commits into
plotly:mainfrom
breken-ai:fix/write-images-layout-size
Open

breken-ai wants to merge 2 commits into
plotly:mainfrom
breken-ai:fix/write-images-layout-size

Conversation

@breken-ai

Copy link
Copy Markdown

Link to issue

Follow-up to #5325, which fixed this for to_image/write_image but not for write_images. I couldn't find an existing issue for the write_images case, and I'm happy to open one if you'd prefer.

Description of change

pio.write_images ignores layout.width/layout.height, and the template's size too, so every figure is exported at the default 700x500. write_image and to_image have used the argument, then layout, then template, then defaults order since #5325. write_images still passed d["width"] or defaults.default_width straight to Kaleido. Batch-exporting a figure built for 1200x300 therefore gives a squashed 700x500 image, while exporting the same figure alone gives the right size. This PR moves the width/height resolution from to_image into a small _resolve_width_height helper and uses it for every figure in write_images.

Demo

import plotly.graph_objects as go
import plotly.io as pio

fig = go.Figure(go.Scatter(x=[1, 2], y=[1, 2]), layout=dict(width=800, height=600))
pio.write_image(fig, "single.svg")      # 800x600
pio.write_images([fig], ["batch.svg"])  # before: 700x500, after: 800x600

Testing strategy

I added test_write_images_width_height_priority next to test_width_height_priority in tests/test_optional/test_kaleido/test_kaleido.py. It exports three figures through real Kaleido and checks the SVG sizes: layout size only, a width argument overriding the layout, and no size at all. On main it fails with (700, 500) != (800, 600), and with this change it passes. The rest of test_kaleido.py passes too, apart from test_image_renderer, which needs IPython and also fails on main in my environment. ruff format --check is clean.

Additional information (optional)

to_image behaves exactly as before, since the helper holds the same expression. I found this bug and wrote the fix with the help of an AI coding assistant, and I checked the change and the test output myself.

Guidelines

breken-ai and others added 2 commits September 29, 2026 20:51
plotly#5325 made to_image and write_image fall back to layout.width/height and
the template layout size before the plotly.io defaults, but write_images
still passed the 700x500 defaults to Kaleido for every figure. Move the
width/height resolution into a helper and use it in both paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant