【问题标题】:How to change default dcc.Graph template in Plotly Dash?如何更改 Plotly Dash 中的默认 dcc.Graph 模板?
【发布时间】:2020-04-28 22:22:57
【问题描述】:

我正在尝试将默认的 plotly 模板更改为“seaborn”或“plotly_dark”。虽然它在 plotly 中有效,但在使用 plotly 的 Dash 中似乎不起作用。即使在指定 template='plotly_dark' 后,它仍然显示默认的 plotly 模板。

这里是没有指定模板的代码:

return dcc.Graph(
    id='example-graph',
    figure={
        'data': [
            {'x': df_most_lines.Cast, 'y': df_most_lines.Lines, 'type': 'bar', 'name': 'input_data'}
        ],
        'layout':  { 'paper_bgcolor':'rgba(0,0,0,0)',
                'plot_bgcolor':'rgba(0,0,0,0)',
            'title': 'WHO USED THE MOSE LINES?'
        }
    }
)

【问题讨论】:

    标签: python plotly-dash


    【解决方案1】:

    如果您使用 go.Figure() 而不是字典,您的代码应该可以工作:

    import plotly.graph_objects as go
    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    
    app = dash.Dash()
    
    app.layout = html.Div([
    
        dcc.Graph(figure=go.Figure(data=go.Bar(x=['a', 'b', 'c', 'd'], y=[1, 2, 3, 4]),
                                   layout=dict(template='plotly_dark'))),
    
    ])
    
    app.run_server(debug=False)
    

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 2010-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      相关资源
      最近更新 更多