简体   繁体   中英

Programmatically make plot areas have the same dimensions in Plotly Dash dashboard

While the below two graphs are rendered in the same container div , it seems the axis labeling (amongst the other things???) is causing the actual render area to be smaller on the top plot

轴标签错误

When the axis is modified this somewhat corrects:

在此处输入图像描述

Ultimately I'm wondering if its possible to make the plot areas be exactly the same width (regardless of axis titles/labels/etc)?

Here's the relevant code that goes with the above explanation:

    ...

html.Div([
    html.Div(
        id="row-1-2",
        children=[
            html.Div(
                [
                    dcc.Graph(
                        id='plot1',
                        style={"height": "20vh", "margin": "0px"},
                    ),
                ],
                className="twelve columns",
            )
        ],
        className="row",
        style={"margin": "0px"},
    ),
    html.Div(
        id="row-2-2",
        children=[
            html.Div(
                [
                    dcc.Graph(
                        id='plot2',
                        style={"height": "20vh", "margin": "0px"},
                    ),
                ],
                className="twelve columns",
            )
        ],
        className="row",
        style={"margin": "0px"},
    ),
], className="three columns"),

    ...

Try to use CSS property width to render same width graph sizes like -

html.Div([
    html.Div(
        id="row-1-2",
        children=[
            html.Div(
                [
                    dcc.Graph(
                        id='plot1',
                        style={"height": "20vh", "width":"80vw", margin": "0px"},
                    ),
                ],
                className="twelve columns",
            )
        ],
        className="row",
        style={"margin": "0px"},
    ),
    html.Div(
        id="row-2-2",
        children=[
            html.Div(
                [
                    dcc.Graph(
                        id='plot2',
                        style={"height": "20vh", "width":"80vw", "margin": "0px"},
                    ),
                ],
                className="twelve columns",
            )
        ],
        className="row",
        style={"margin": "0px"},
    ),
], className="three columns"),

    ...

seems like the closest I can get it is by setting automargin to false in the actual figure:

fig.update_layout({"xaxis": {"automargin": False}})

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM