Skip to content

Kaleido ignores width/height from Plotly figure #12

Closed

Description

@kvanderwijst

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!

Activity

  1. jonmmease commented on Jul 17, 2020

    @jonmmease
    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:

    https://github.com/plotly/Kaleido/blob/798fa989c594d370b4b2956a6579fe9c5e74dfae/repos/kaleido/py/kaleido/scopes/plotly.py#L71-L72

    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:

    https://github.com/plotly/Kaleido/blob/798fa989c594d370b4b2956a6579fe9c5e74dfae/repos/kaleido/js/src/plotly/constants.js#L22-L27

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

  2. nicolaskruchten commented on Jul 17, 2020

    @nicolaskruchten

    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.

  3. nicolaskruchten commented on Jul 17, 2020

    @nicolaskruchten

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

  4. jonmmease commented on Jul 17, 2020

    @jonmmease
    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.

  5. nicolaskruchten commented on Jul 17, 2020

    @nicolaskruchten

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions