Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Follow-up to #5325, which fixed this for
to_image/write_imagebut not forwrite_images. I couldn't find an existing issue for thewrite_imagescase, and I'm happy to open one if you'd prefer.Description of change
pio.write_imagesignoreslayout.width/layout.height, and the template's size too, so every figure is exported at the default 700x500.write_imageandto_imagehave used the argument, then layout, then template, then defaults order since #5325.write_imagesstill passedd["width"] or defaults.default_widthstraight 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 fromto_imageinto a small_resolve_width_heighthelper and uses it for every figure inwrite_images.Demo
Testing strategy
I added
test_write_images_width_height_prioritynext totest_width_height_priorityintests/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. Onmainit fails with(700, 500) != (800, 600), and with this change it passes. The rest oftest_kaleido.pypasses too, apart fromtest_image_renderer, which needs IPython and also fails onmainin my environment.ruff format --checkis clean.Additional information (optional)
to_imagebehaves 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