python - 破折号中的图形布局

标签 python css plotly plotly-dash

我有一个非常普遍的问题:如何管理由 python 中的 dash-plotly 制作的仪表板中的分区/图表的布局。假设我有以下代码:

def charts():
    data = [go.Bar(
        x=['giraffes', 'orangutans', 'monkeys'],
        y=[20, 14, 23] )]
    return data
app = dash.Dash()

app.layout = html.Div([

    html.Div([
        dcc.Graph(
            id='figure1',
            figure=charts()
        ),
    ], style={'width': '49%', 'display': 'inline-block'}),
    html.Div([
        dcc.Graph(
            id = 'figure2',
            figure=charts()
        ),
        dcc.Graph(
            id='figure3',
            figure=charts()
        )
    ], style= {'width': '49%', 'display': 'inline-block'})
])

if __name == '__main__':
    app.run_server()

我想要的是:

+++++++++++++++++++++++
+         +  figure2  +
+ figure1 +           +
+         +  figure3  + 
+++++++++++++++++++++++

但是我得到的是:

+++++++++++++++++++++++
+         +  figure2  +
+         +           +
+ figure1 +  figure3  + 
+++++++++++++++++++++++

问题在这里:

  1. 一般来说,如何管理参数来改变布局?
  2. 使用宽度来管理宽度,但如何管理高度(在这种情况下,我希望figure1的高度是figure2或figure3的两倍)?

最佳答案

dcc.Graph 的布局标签用于设置图形的布局,而不是 HTML 的布局。 我通常使用 bootstrap 或任何其他 CSS 来获取网格配置,并且很容易使用网格系统来对齐事物。您可以通过在代码中附加此行来添加外部或内联样式表。根据您使用的 CSS 更改“external_url”。

app.css.append_css({"external_url": "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"})

关于python - 破折号中的图形布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46926816/

相关文章:

python - 从 python 执行一个 .sh 文件,指示绝对路径

python - 如何将文本文件拆分成 block ?

html - Plotly 无法在 Shiny 的 HTML 功能中工作

python - Plotly:如何仅将垂直和水平线(十字准线)显示为 hoverinfo?

python - 无法从Python中的列表列表中删除字符串

python - 在 python 中导入 vim 返回错误

html - table 可以看起来像这样吗?

javascript - 如何在 Angular js中将一个表行移动到另一个表?

html - Jekyll latex 没有出现在远程但出现在本地

Python Plotly Sankey 图未显示