[Python] IPywidgets GrespecLayout - Don't show the full output

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    The following code only displays the last chart, but not the first three. I tried adapting both parent and item layout, but could not get it to work.

    import plotly.express as px
    import ipywidgets as widgets
    from ipywidgets import GridspecLayout, Layout, Output


    com_lay = Layout(
    width='100%',
    height='300px',
    border='1px solid gray',
    overflow='auto'
    )

    # Create output widgets
    out_bar = Output(layout=com_lay)
    out_line = Output(layout=com_lay)
    out_scat = Output(layout=com_lay)
    out_hist = Output(layout=com_lay)

    # Load and show plots
    df = px.data.iris()
    with out_scat:
    fig = px.scatter(df, x='sepal_width', y='sepal_length', color='species')
    fig.show()

    df_tips = px.data.tips()
    with out_bar:
    fig = px.bar(df_tips, x='day', y='total_bill', color='sex', barmode='group')
    fig.show()

    df_line = px.data.gapminder().query("country == 'Canada'")
    with out_line:
    fig = px.line(df_line, x='year', y='gdpPercap', title='GDP per Capita - Canada')
    fig.show()

    with out_hist:
    fig = px.histogram(df_tips, x='total_bill', nbins=30, color='sex')
    fig.show()

    # Set up grid layout
    grid = GridspecLayout(
    4, 1,
    layout=Layout(
    width='100%',
    height='auto',
    grid_gap='10px'
    )
    )

    # Assign plots to grid
    grid[0, 0] = out_line
    grid[1, 0] = out_bar
    grid[2, 0] = out_scat
    grid[3, 0] = out_hist

    grid



    How can I get all four charts to display?

    Continue reading...

Compartilhe esta Página