Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kaleido ignores width/height from Plotly figure #12

Closed
kvanderwijst opened this issue Jul 17, 2020 · 5 comments · Fixed by #18
Closed

Kaleido ignores width/height from Plotly figure #12

kvanderwijst opened this issue Jul 17, 2020 · 5 comments · Fixed by #18
Labels
bug something broken

Comments

@kvanderwijst
Copy link

First of all, thanks for the great work on the Kaleido package -- great improvement over Orca architecture!

However, the width and height attributes as set in a Figure layout are ignored: you have to specify them explicitly in the write_image command. This is not required when using Orca. It would be very nice to have this feature also for Kaleido.

Thanks!

@jonmmease jonmmease added bug something broken language: Python labels Jul 17, 2020
@jonmmease
Copy link
Collaborator

Hi @kvanderwijst, thanks for the encouraging words and for giving Kaleido a try!

I can confirm what you're seeing and this is definitely an oversight. Until we get a fix out, you can work around this by setting the default width/height to None like this:

import plotly.io as pio
pio.kaleido.scope.default_width = None
pio.kaleido.scope.default_height = None

Technical details:

The culprits are these lines:

width = width if width is not None else self.default_width
height = height if height is not None else self.default_height

For width, we should check the figure's layout.width and layout.template.layout.width properties before falling back to self.default_width. Same for height.

In the meantime, this can be worked around this by setting the default width/height to None like this:

import plotly.io as pio
pio.kaleido.scope.default_width = None
pio.kaleido.scope.default_height = None

In this case, the figure's width and height will be used if they are available, otherwise the are chosen using the defaults defined in the JavaScript layer here:

dflt: {
format: 'png',
scale: 1,
width: 700,
height: 500
},

Note: This issue only affects the Python Plotly scope, other wrappers of the Kaleido C++ core do not have this problem.

@nicolaskruchten
Copy link

Interestingly, Orca also ignores the built-in height and width when using it with fig.show("png") for example. Would be great to get a fix for both.

@nicolaskruchten
Copy link

(both renderers and writers I mean... fixing Orca in post-4.9 doesn't make much sense)

@jonmmease
Copy link
Collaborator

Orca also ignores the built-in height and width when using it with fig.show("png")

This is probably a change we'll need to make in the plotly.py renderer code since they also have default width/height logic.

@nicolaskruchten
Copy link

OK, let's pursue here: plotly/plotly.py#2651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants