Skip to content

Plotly.js is not height responsive #5270

Closed

Description

@MarcSkovMadsen

I'm using Plotly.js via Python. I'm also a user of other plotting libraries like Bokeh, Vega/ Altair and Echarts. And I can see that the responsiveness functionality of plotly.js is just not as robust, fast and seamless as the others.

The one thing where I can point to a reproducible example right now is height responsiveness.

If you take the example at https://plotly.com/javascript/responsive-fluid-layout/ you can see its not height responsive.

This is a major problem if you want to make responsive layouts. For example for mobile. But also if you want to put Plotly inside resizable divs and similar.

plotly-not-resizable

Activity

  1. MarcSkovMadsen commented on Nov 13, 2020

    @MarcSkovMadsen
    Author

    Additional Context

    You can experiment with the behavior of Plotly vs other plotting libraries here.

    App: https://awesome-panel.org/streaming-plots
    Code: https://github.com/MarcSkovMadsen/awesome-panel/blob/master/application/pages/streaming_plots/streaming_plots.py

    plot-not-responsive-streaming

    Echarts also have a problems. But those where on Panels side and have been solved in the Panel Master branch.

  2. MarcSkovMadsen commented on Nov 13, 2020

    @MarcSkovMadsen
    Author

    Additional Context 2

    Another reproducible example can be found here holoviz/panel#1770 (comment)

    98850094-87da1000-2454-11eb-9c74-be10e8e5914c

    import numpy as np
    import altair as alt
    import pandas as pd
    import panel as pn
    from streamz.dataframe import DataFrame as sDataFrame
    import hvplot.pandas
    import plotly.express as px
    
    plotly_pane = pn.pane.Plotly(sizing_mode="stretch_both", config={'responsive': True})
    
    def update_plotly(data):
        data = pd.concat(data).reset_index()
        plot = px.line(data, y="y", title='Plotly', template="plotly_dark")
        plot.layout.autosize=True
        plotly_pane.object = plot
    
    df = sDataFrame(example=pd.DataFrame({"y": []}, index=pd.DatetimeIndex([])))
    window_stream = df.cumsum().stream.sliding_window(50)
    
    plotly_sink = window_stream.sink(update_plotly)
    
    def emit():
        df.emit(pd.DataFrame({"y": [np.random.randn()]}, index=pd.DatetimeIndex([pd.datetime.now()])))
    emit()
    pn.state.add_periodic_callback(emit, period=100, count=500)
    
    layout = pn.template.ReactTemplate(
        site="Awesome Panel",
        title="Streaming w. Echarts",
        theme=pn.template.react.DarkTheme,
        row_height=200,
    )
    layout.main[0:2, 0:6]=pn.layout.Card(plotly_pane, header="PLOTLY", sizing_mode="stretch_both")
    layout.servable()

    run the file with panel serve FILENAME.PY.

  3. changed the title [-]Plot.js is not height responsive[/-] [+]Plotly.js is not height responsive[/+] on Nov 13, 2020
  4. Erhannis commented on Dec 3, 2020

    @Erhannis

    I think the problem is that the div's height wraps to its contents. If I open the debugger (specifically on the codepen of one of the examples) and set height to 100% on the plot div, and every element above it (back up to and including <html>), the plot does resize height.

  5. MarcSkovMadsen commented on Dec 4, 2020

    @MarcSkovMadsen
    Author

    Thanks. I can see adding height 100% is the solution. Thanks

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions